Hi!
I’m trying to perform a Bulk Upsert for documents. I understand this can’t be done natively in Meteor:Mongo
and that the Node MongoDB lib has to be used with rawCollection
instead.
I have the following
const bulkUpserts = [];
for (let doc of docs) {
bulkUpserts.push({
updateOne: {
filter: {
fizz: doc.buzz
},
update: doc,
upsert: true,
setOnInsert: {
"foo": "bar",
"createdBy": Meteor.userId(),
"createdDate": new Date()
}
}
});
}
Collection.rawCollection().bulkWrite(bulkUpserts);
The issue with ^ is that the setOnInsert
doesn’t seem to work. My foo
s aren’t being set. Looks like setOnInsert
isn’t available as an option for updateOne
. What’s the alternative though? I surprisingly cannot find a way to do this in Meteor yet.
Thanks!