Skip to content

Instantly share code, notes, and snippets.

@blackwright
Created April 28, 2017 15:24
Show Gist options
  • Save blackwright/ac6866d59ce772367ccfd1d06f5ba5c5 to your computer and use it in GitHub Desktop.
Save blackwright/ac6866d59ce772367ccfd1d06f5ba5c5 to your computer and use it in GitHub Desktop.
Mongoose Seeds Clean
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