Skip to content

Instantly share code, notes, and snippets.

@IronCore864
Last active February 19, 2019 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IronCore864/feff9dadb989b35df7cd4e34ff40fa71 to your computer and use it in GitHub Desktop.
Save IronCore864/feff9dadb989b35df7cd4e34ff40fa71 to your computer and use it in GitHub Desktop.
//@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