亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何執行批量更新插入

如何執行批量更新插入

森欄 2023-05-11 16:03:19
我正在嘗試對文檔執行批量更新插入。我知道這不能在本地完成Meteor:Mongo,必須使用 Node MongoDB librawCollection代替。我有以下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);^ 的問題是它setOnInsert似乎不起作用。我foo的沒有設置??雌饋韘etOnInsert不能作為updateOne. 有什么選擇呢?令人驚訝的是,我還找不到在 Meteor 中執行此操作的方法。謝謝!
查看完整描述

1 回答

?
HUWWW

TA貢獻1874條經驗 獲得超12個贊

我最終使用


const bulk = LineItems.rawCollection().initializeUnorderedBulkOp();


for (let doc of docs) {    

  bulk.find({

    fizz: doc.buzz

  }).upsert().updateOne({

    $set: doc,

    $setOnInsert: {

      _id: Random.id(),

      "foo": "bar",

      "createdBy": Meteor.userId(),

      "createdDate": new Date()

    }

  });

}

bulk.execute().then().catch(error => console.error(error));


查看完整回答
反對 回復 2023-05-11
  • 1 回答
  • 0 關注
  • 128 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號