Is there a way to check if Mongodb bulk has some operations to do before calling .execute() on it? I am pretty sure I don't send any empty objects to insert but keep getting this error on one document
Invalid Operation, No operations in bulk
Here is some code:
bulk.find({"AcctSessionId":insert['AcctSessionId']}).upsert().update({$set:insert});
and insert object looks like this
{ AcctStatusTypeU: '3',
AcctSessionId: '1183628512-105130252',
h323setuptimeU: '<sip:[email protected]>',
h323connecttimeU: Sun Mar 08 2015 19:30:37 GMT+0100 (CET),
AcmeSessionEgressRealmU: '620',
AcmeSessionIngressRealmU: 'CORE_PSX'
}
I see my objects inserted but still get this error. By the way this is a Nodejs driver I am talking about and I am using UNorderedBulkOp to insert documents.
In MongoDB, we can check the existence of the field in the specified collection using the $exists operator. When the value of $exists operator is set to true, then this operator matches the document that contains the specified field(including the documents where the value of that field is null).
Bulk() Bulk operations builder used to construct a list of write operations to perform in bulk for a single collection. To instantiate the builder, use either the db. collection. initializeOrderedBulkOp() or the db.
Bulk operations are actions that are performed on a large scale. Example bulk operations tasks include importing or exporting items, changing prices on a mass scale, and assigning products to a warehouse. For each individual task of a bulk operation, the system creates a message that is published in a message queue.
bulkWrite() method provides the ability to perform bulk insert, update, and delete operations. MongoDB also supports bulk insert through the db. collection.
I run into the same problem. Check bulk.length
if (bulk.length > 0) {
// run bulk operations
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With