pizzarob
pizzarob

Reputation: 12049

MongoDB Bulk Write Not Updating

From what I see in the docs I'm doing this correctly, but I don't know why it's not updating the document. http://mongodb.github.io/node-mongodb-native/2.2/api/Collection.html#bulkWrite

const updates = [
{
  "updateOne": {
    "filter": {
      "Item": {
        "$oid": "59bdbf4f857c5b78b3a4c400"
      },
      "Path": "ShortDescription"
    },
    "update": {
      "$set": {
        "Value": "100 knotzzzz"
      }
    }
  }
}
]

await mongoose.connection.db.collection('productdata').bulkWrite(updates);

Am I doing something wrong?

Upvotes: 0

Views: 2331

Answers (1)

pizzarob
pizzarob

Reputation: 12049

I am using the initializeUnorderedBulkOp method and it's working, but I'd still like to know why bulk write didn't work. Here is the code that is working for me.

  const bulk = mongoose.connection.db.collection('productdatas').initializeUnorderedBulkOp();

  data.forEach(([Path, Value]) => {
    bulk.find({ Item: new ObjectID(_id), Path }).updateOne({
      $set: {
        Value,
      },
    });
  });

  await bulk.execute();

Upvotes: 1

Related Questions