Meteor Mongodb Bulk Update by _id not working


#1

I’m trying to perform following bulk Update Operation by _id:

let bulk = Transactions.rawCollection().initializeOrderedBulkOp();
                
transactions.forEach((t) => {             
   let query = { '_id' : new Meteor.Collection.ObjectID(t._id._str) };
   bulk.find( query ).update( { $set: { balance: t.balance, updated_at: new Date() } } );
});
bulk.execute(Meteor.bindEnvironment((err, res) => {
     if (!err) {
             callback(null, true);
      } else {
             console.log("Error Ocurred");
             callback(true, null);
       }
}));

But This find query by Id is not working. If I do query by any other field It works just fine. But I can’t do that because Collection has only one Unique field as ‘_id’.
Help Needed. TIA


#2

Pretty late, but, I just needed the same thing, and found the solution. So, for future reference:

According to this Stack Overflow:

Mongo.Collection.ObjectID is not a plain ObjectId representation, and is actually a complex object for Meteor internal use.

The solution is to use MongoInternals:

let query = {_id: new MongoInternals.NpmModule.ObjectID(t._id._str) }