Last active
November 20, 2017 21:51
-
-
Save mosbth/14960b15726930e69177e76c7fa1e878 to your computer and use it in GitHub Desktop.
async await
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
/** | |
* 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