node.js - Meteor Mongo BulkOp turning ObjectID into plain object -
while using meteor, access underlying node mongo driver can make bulk updates , inserts.
const bulk = coll.rawcollection().initializeorderedbulkop(); bulk.insert({key_id: mongo.collection.objectid()}); // note key_id objectid ... bulk.execute(); but value of key_id fields ends being plain subdocument {_str: '...'} when in database after insert.
is there way use bulk operations in node's mongo library (whatever meteor uses) , keep objectid's mongo's objectid type?
(there's many posts nature of different id types, , explaining minimongo, etc. i'm interested bulk operations converting objectid's plain objects, , solving issue.)
on native method need grab native implementation. should able access loaded driver through mongointernals [...]
mongo.collection.objectid not plain objectid representation, , complex object meteor internal use. hence why native methods don't know how use value.
so if have field objectid, , you're using method of meteor collection's rawcollection (for example,
.distinct.aggregate.initializeorderedbulkop.initializeunorderedbulkop
), you'll want convert objectid's using
const convertedid = new mongointernals.npmmodule.objectid( originalid._str ); // use in 1 of arguments function or const query = {_id: convertedid}; before calling method on them.
Comments
Post a Comment