MongoDB更新嵌套数组中的字段 [英] MongoDB updating fields in nested array
本文介绍了MongoDB更新嵌套数组中的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
MongoDB更新嵌套数组中的字段
MongoDB updating fields in nested array
如何在照片数组中将播放设置为播放照片?
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"
}]
推荐答案
你不能。位置运算符仅适用于文档层次结构中的第一个数组。因此,你不能操作更深层的nester数组的单个元素。
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屋!
查看全文