更改我所有文档的嵌套文档值 [英] Change all my documents nested document value
问题描述
在mongos shell中,我将如何遍历并将reviews.category
中的每个文档更改为类别2"
In mongos shell how would I go through and change every document in reviews.category
to "category 2"
我的文档结构:
{
"_id": ObjectId("4fb3f443b1445d24fc000000"),
"reviews": {
"0": {
"category": "category 1"
},
"1": {
"category": "category 1"
},
"2": {
"category": "category 1"
},
"3": {
"category": "category 1"
}
}
}
推荐答案
您将必须在应用程序代码中自行执行此操作,方法是查询文档并遍历所有嵌套的文档;然后将其保存回MongoDB.
You will have to do this yourself in your application code, by querying the document, and looping over all of your nested documents; and then save it back to MongoDB.
为了防止出现这种情况,请查看比较和交换部分,网址为 http://www.mongodb.org/display/DOCS/Atomic+Operations
In order to prevent race conditions with this, please have a look at the section compare and swap at http://www.mongodb.org/display/DOCS/Atomic+Operations
当前有一个打开的票证可将此功能添加到MongoDB.您可能需要对其进行投票: https://jira.mongodb.org/browse/SERVER-1243
There is currently an open ticket for this to add this functionality to MongoDB. You might want to up-vote it: https://jira.mongodb.org/browse/SERVER-1243
这篇关于更改我所有文档的嵌套文档值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!