2013-12-10 83 views
1

我想插入數組元素,其中Title是'Cities',但是它不插入或插入到新數組中,而不是Links.Link。任何想法我做錯了什麼。我曾嘗試推動和$ addToSet添加新元素到Mongo文檔

{ 
    "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' }}} 
     } 
    } 
) 

但它不如下插入到正確的地方

回答

1

更新查詢:

db.PopularDestinationsUk.update({Id: "125570", "Component.Title" : "cities"}, {$push : {"Component.$.Links.Link" : {Text: 'NEW',Url: 'NEW',Title: 'NEW'}}}) 
+0

哇,這是快速和它的工作。謝謝,我一直試圖弄清楚這個年齡段 – PaulManningBiz

+0

不客氣。 –

相關問題