
這是我在控制器中的代碼,我從我的谷歌日歷 API 獲取記錄,然后將該資料傳遞給該函式,插入檔案(記錄)的函式內部的代碼如下所示:
Holiday.bulkWrite(
holidays.map((holiday) => ({
updateOne: {
filter: { holidayId: holiday.id },
update: { $set: holiday },
upsert: true,
},
}))
)
uj5u.com熱心網友回復:
很難說出究竟是什么問題,因為它與 Mongo 無關,而是與代碼相關,從看起來你只是為過濾器使用了錯誤的欄位。
holiday.id為空,我們可以看到“插入”的檔案沒有這樣的欄位。您基本上正在執行以下更新:
db.collection.update({
holidayId: null
},
{
"$set": {
holidayId: "123"
... other fields
}
},
{
"upsert": true
})
我相信這個簡單的修復可以解決您的問題,更改.id為.holidayId:
Holiday.bulkWrite(
holidays.map((holiday) => ({
updateOne: {
filter: { holidayId: holiday.holidayId },
update: { $set: holiday },
upsert: true,
},
}))
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/524246.html
上一篇:洗掉嵌套檔案-貓鼬
