我在蒙戈数据库中的下列对象命名的音乐。
我想更新其中的体裁是垃圾
乐队的名字是涅槃
专辑名称是没关系
轨道顺序1
MongoDB的更新深阵列
和改变轨道的名称为“气味喜欢青少年的精神!”。
我试着位置运营商打,但不能很 摸不着头脑。
{
genre : "Grunge",
bands : [ {
name : "Nirvana",
albums : [ {
name : "Nevermind",
tracks : [ {
name : "Smell Like Teen Spirit",
order : 1,
duration : 301
},
{
name : "In Bloom",
order : 2,
duration : 254
} ]
},
{
name : "In Utero",
tracks : [ {
name : "Server the Servants",
order : 1,
duration : 216
},
{
name : "Scentless Apprentice",
order : 2,
duration : 254
} ]
} ]
},
{
name : "Karma++ : A Nirvina Tribute Band",
albums : [ {
name : "Nevermind",
tracks : [ {
name : "Smell Like Teen Spirit",
order : 1,
duration : 301
},
{
name : "In Bloom",
order : 2,
duration : 254
} ]
},
{
name : "In Utero",
tracks : [ {
name : "Server the Servants",
order : 1,
duration : 216
},
{
name : "Scentless Apprentice",
order : 2,
duration : 254
} ]
} ]
} ]
}
你有没有考虑过改变你的数据库设计?如果你的文档是一个带'流派'属性的'乐队',那么也许会更有意义 - 并且会使这个特定的查询变得更容易。 – Russell 2012-04-26 21:35:01
这只是我能想到的最快的例子。如果我真的要做一个'音乐'数据库,那么我可能会将歌曲作为以艺术家,专辑和流派为阵列的根源;允许像大卫鲍伊/女王的'压力不足'(2名艺术家,多张专辑)。 – JWally 2012-04-26 22:04:53