MongoDB 更新嵌套数组中的字段 [英] MongoDB updating fields in nested array
本文介绍了MongoDB 更新嵌套数组中的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
MongoDB 更新嵌套数组中的字段
MongoDB updating fields in nested array
如何设置播放"?播放照片"在 photos
数组中?
How can I set "play" to "play photo" in the photos
array?
我只知道它的_id
.
"_id": ObjectId("4f41a5c7c32810e404000000"),
"albums": [
{
"_id": ObjectId("4f545d1bc328103812000000"),
"name": "album1" ,
"photos":[{
"_id": ObjectId("4f545d1bc328103812d00000"),
"name":"travel photo"
},{
"_id": ObjectId("4f545d1bc328103812c00000"),
"name":"play"
}]
},
{
"_id": ObjectId("4f545f56c328103c12000000"),
"name": "album2"
},
{
"_id": ObjectId("4f545f68c328103012000000"),
"name": "album3"
},
{
"_id": ObjectId("4f546642c328103c12000001"),
"name": "album4"
}]
推荐答案
你不能.位置运算符仅适用于文档层次结构中的第一个数组.因此,您无法操作更深的嵌套数组的单个元素.
You can't. The positional operator is only available for the first array in your document hierarchy. As such you cannot manipulate individual elements of deeper nester arrays.
这是一个已知问题,计划在此处开发:https://jira.mongodb.org/browse/SERVER-831
It's a known issue and is scheduled for development here : https://jira.mongodb.org/browse/SERVER-831
在那之前,恐怕你必须稍微规范化你的架构.
Until that time you'll have to normalize your schema a bit I'm afraid.
这篇关于MongoDB 更新嵌套数组中的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文