Last active
February 19, 2019 12:12
-
-
Save IronCore864/feff9dadb989b35df7cd4e34ff40fa71 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//@flow | |
import MongoClient from 'mongodb'; | |
import { dbUrl, dbName } from '../config/dbconfig'; | |
async function clean(req: Object, reply: Object): Object { | |
const collections = ['posts', 'boards', 'users', 'comments']; | |
for (let collection of collections) { | |
let client; | |
try { | |
client = await MongoClient.connect(dbUrl, { useNewUrlParser: true }); | |
} catch (err) { | |
console.log('Connection Error!'); | |
console.log(err); | |
} | |
try { | |
const db = client.db(dbName); | |
await db.collection(collection).drop(); | |
console.log(`Collection ${collection} deleted.`); | |
} catch (err) { | |
console.log(`Collection ${collection} error, ${err.codeName}.`); | |
} finally { | |
await client.close(); | |
} | |
} | |
} | |
clean(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment