Skip to content

Instantly share code, notes, and snippets.

@mosbth
Last active November 20, 2017 21:51
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 mosbth/14960b15726930e69177e76c7fa1e878 to your computer and use it in GitHub Desktop.
Save mosbth/14960b15726930e69177e76c7fa1e878 to your computer and use it in GitHub Desktop.
async await
/**
* Reset a collection by removing existing content and insert a default
* set of documents.
*
* @param {string} dns DNS to connect to database.
* @param {string} colName Name of collection.
* @param {string} doc Documents to be inserted into collection.
*
* @throws Error when database hadnling fails.
*
* @return {Promise} Empty.
*/
async function resetCollection(dns, colName, doc) {
const db = await mongo.connect(dns);
const col = await db.collection(colName);
const op1 = await col.deleteMany();
const op2 = await col.insertMany(doc);
db.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment