Mongoose Bulk Save

JS
S
JavaScript

Please avoid using `collection.insertMany(...)` for bulk operations as your validators and plugins will be bypassed.

1FinanceSchema.static('addDataGrid', (dataGrid) => {
2  if(!dataGrid){
3    throw new Error('No payload has been received');
4  }
5  // Bulk Save
6  const models = [];
7  dataGrid.forEach(element => {
8    models.push(new FinanceModel(element));
9  });
10  return Promise.all(
11    models.map(model => model.save())
12  )
13});

Created on 8/4/2018