簡體   English   中英

如何在貓鼬中使用findByIdAndUpdate填充數組

[英]How to fill an array with findByIdAndUpdate in Mongoose

我目前正在嘗試做一個算法來完成1的表。我的表由定義:

const content = new Array(content_size)
 
for (let i = 0; i < content_size; i++) {
     content[i] = new Array(content_size)
     content[i].fill(0)
}

content_size = 100。

我想做的是使用Mongoose的findByIdAndUpdate()函數,僅使用10填充此表在Mongo中

findByIdAndUpdate用於一個文檔。 對於多個文檔,可以使用帶有true的update標記。

更新需要3個參數

  1. 詢問
  2. 更新資料
  3. 選件

這里的查詢選擇器的功能與find()中的相同。

db.COLLECTION_NAME.update({}, {$set: {fill: 1}}, { multi: true })

有關更多信息,請檢查: https : //docs.mongodb.com/manual/reference/method/db.collection.update/

我希望這能解決您的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM