[英]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.