node-mongo-seeds: Fix { [MongoError: Invalid Operation, No operations in bulk] name: 'MongoError' }

Depending on what you’re inserting, you can the error: { [MongoError: Invalid Operation, No operations in bulk] name: 'MongoError' }

Need to figure out what is causing this and how to fix it.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 17 (9 by maintainers)

Commits related to this issue

Most upvoted comments

I just found out this error may happen if an empty array is passed. I could swear I’m not sending empty arrays, but I’ll do some tests to verify.

Just check if the bulk instance has operations before calling execute with this function:

const BulkHasOperations = (b) => b && b.s && b.s.currentBatch && b.s.currentBatch.operations && b.s.currentBatch.operations.length > 0;
...
const bulk = db.collection('something').initializeUnorderedBulkOp();
...
BulkHasOperations(bulk) && bulk.execute();