第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

如何執(zhí)行批量更新插入

如何執(zhí)行批量更新插入

森欄 2023-05-11 16:03:19
我正在嘗試對文檔執(zhí)行批量更新插入。我知道這不能在本地完成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的沒有設(shè)置??雌饋韘etOnInsert不能作為updateOne. 有什么選擇呢?令人驚訝的是,我還找不到在 Meteor 中執(zhí)行此操作的方法。謝謝!
查看完整描述

1 回答

?
HUWWW

TA貢獻1874條經(jīng)驗 獲得超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));


查看完整回答
反對 回復(fù) 2023-05-11
  • 1 回答
  • 0 關(guān)注
  • 137 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號