我想插入标题是'Cities‘的数组元素,但它不插入或插入到新数组而不是Links.Link中。知道我做错了什么吗。我已经尝试过push和$addToSet
{
"Component" : [
{
"Title" : "regions",
"Links" : {
"Link" : [
{
"Text" : "Tyrol",
"Url" : "/1xf-en700p/cheap-holidays-tyrol",
"Title" : "Cheap holidays Tyrol"
},
{
"Text" : "Browse Regions ",
"Url" : "/1xf-en6ujz-10ts/cheap-holidays-austria/regions",
"Title" : "Cheap holidays Austria",
"Style" : "BrowseForMore"
}
]
}
},
{
"Title" : "cities",
"Links" : {
"Link" : [
{
"Text" : "Maria Saal",
"Url" : "/1xf-enu4dl/cheap-holidays-maria-saal",
"Title" : "Cheap holidays Maria Saal"
},
{
"Text" : "Nessendorf",
"Url" : "/1xf-enwvu8/cheap-holidays-nessendorf",
"Title" : "Cheap holidays Nessendorf"
},
]
}
},
],
"Id" : "125570",
}
with
var pd = { Text: 'test',Url: 'test',Title: 'test' };
db.PopularDestinationsUk.update
(
{
Id: '125570'
,'Component.Title': 'cities'}
}
,
{
$push:
{
'Component.Link.$.Links { Text: 'NEW',Url: 'NEW',Title: 'NEW' }}}
}
}
)但是它没有插入到正确的位置
发布于 2013-12-10 19:38:26
按如下方式更新您的查询:
db.PopularDestinationsUk.update({Id: "125570", "Component.Title" : "cities"}, {$push : {"Component.$.Links.Link" : {Text: 'NEW',Url: 'NEW',Title: 'NEW'}}})https://stackoverflow.com/questions/20493347
复制相似问题