[英]Document download counter? Using Node.js, express, mongo, mongoose
[英]How to replace a document in mongo db using node.js
任何人都可以幫助如何使用node.js中的replaceone函數替換mongodb中的整個文檔
從名稱和文檔來看, replaceOne用於根據過濾器替換集合中的單個文檔。
文檔中的語法
db.collection.replaceOne(
<filter>,
<replacement>,
{
upsert: <boolean>,
writeConcern: <document>,
collation: <document>,
hint: <document|string> // Available starting in 4.2.1
}
)
要替換多個文檔,
1) 使用remove()方法刪除所需的文檔,然后運行insertMany()方法。
或者
2) 使用updateMany()方法更新多個匹配過濾器的文檔,其中包含一組特定的值。
db.collection.updateMany(
<filter>,
<update>,
{
upsert: <boolean>,
writeConcern: <document>,
collation: <document>,
arrayFilters: [ <filterdocument1>, ... ],
hint: <document|string> // Available starting in MongoDB 4.2.1
}
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.