expanded on migration support

This commit is contained in:
Wyatt Johnson
2018-01-25 13:07:29 -07:00
parent ef7693afa5
commit e6f796e99c
8 changed files with 157 additions and 126 deletions
+19
View File
@@ -0,0 +1,19 @@
/**
* processUpdates processes batches of updates on the given model.
*
* @param {Object} model mongoose model that should perform the operations on
* @param {Array<Object>} updates array of updates to execute
*/
const processUpdates = async (model, updates) => {
// Create a new batch operation.
const bulk = model.collection.initializeUnorderedBulkOp();
for (const { query, update } of updates) {
bulk.find(query).updateOne(update);
}
// Execute the bulk update operation.
await bulk.execute();
};
module.exports = { processUpdates };