mongodb 中的“deletemany”和“remove”有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35691647/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the difference between "deletemany" and "remove" in mongodb?
提问by look
What's the difference between the two commands here?db.collection.deleteMany({condition})
db.collection.remove({condition})
这里的两个命令有什么区别?db.collection.deleteMany({condition})
db.collection.remove({condition})
采纳答案by Dave Amit
As far as I can say,
据我所知,
db.collection.deleteMany
db.collection.deleteMany
Returns:
A document containing:
> A boolean acknowledged as true if the operation ran with write concern or false if write concern was disabled
> deletedCount containing the number of deleted documents
Where as
然而
db.collection.remove
db.collection.remove
return WriteResult
返回写入结果
And to remove a single document, there a similar command, db.collection.removeOne
where as with db.collection.remove
you need to set and option called justOne
option to limit delete to 1 document.
要删除单个文档,有一个类似的命令,db.collection.removeOne
其中db.collection.remove
您需要设置和选项称为justOne
选项以将删除限制为 1 个文档。
Otherwise I guess they are similar.
否则我猜他们是相似的。
node.js drivers
node.js 驱动程序
When talking about node.js drivers
, remove
has been deprecated (and may be removed in future releases) and deleteOne
or deleteMany
.
在谈论 时node.js drivers
,remove
已被弃用(并且可能会在未来版本中删除)和deleteOne
或deleteMany
。
Hope this makes sense ....
希望这是有道理的......
回答by Revol89
They do the same. The difference is the valuesthat return.
他们做同样的事情。不同之处在于返回的值。
With remove()
:
与remove()
:
> db.ticker.remove({"name": "Bitcoin"})
WriteResult({ "nRemoved" : 2 })
With deleteMany()
:
与deleteMany()
:
> db.ticker.deleteMany({"name": "Bitcoin"})
{ "acknowledged" : true, "deletedCount" : 2 }