简体   繁体   中英

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?

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM