Created
April 28, 2017 15:24
-
-
Save blackwright/ac6866d59ce772367ccfd1d06f5ba5c5 to your computer and use it in GitHub Desktop.
Mongoose Seeds Clean
This file contains hidden or 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
const mongoose = require('mongoose'); | |
module.exports = () => { | |
// Get all collections | |
let collections = mongoose | |
.connection | |
.collections; | |
// Get collection names | |
let collectionKeys = Object.keys(collections); | |
// Store promises | |
let promises = []; | |
// For each collection | |
collectionKeys.forEach((key) => { | |
// Remove all documents | |
const promise = collections[key].remove(); | |
promises.push(promise); | |
}); | |
return Promise.all(promises); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment