2016-06-30 3 views
1

複数のネストされたドキュメントに別のドキュメントを挿入しようとしています。あなたはそれを解決するための他のアイデアはありますか?おかげ複数のネストされた要素をMongoDBに挿入する

{ 
"_id" : ObjectId("576bddaa08b8f7dc20000033"), 
"Name" : "Business", 
"Image" : "fa fa-dollar", 
"Description" : "Money, Capitalism, Business", 
"NoForums" : 0, 
"NoTopics" : 0, 
"NoComments" : 0, 
"NoUsers" : 0, 
"CoverImage" : "https://www.rocklandtrust.com/assets/content/txh9vvwg/2014/08/06/business%20savings.jpg", 
"Children" : [ 
    { 
     "_id" : ObjectId("57715e0608b8f7441b00002d"), 
     "Name" : "Business School", 
     "URLName" : "Business-School", 
     "Image" : "http://www.small-business-website.net/wp-content/uploads/2016/04/How-to-achieve-a-successful-business-sale-128x128.jpg", 
     "Description" : "Everything about Business Schools", 
     "NoForums" : 0, 
     "NoTopics" : 0, 
     "NoComments" : 0, 
     "NoUsers" : 0, 
     "CoverImage" : "http://www.incae.edu/sites/default/files/styles/slideshow-un-medio/public/primerdiamba2010_018.jpg?itok=LfZmxw14", 
     "Children" : [] 
    }, 
    { 
     "_id" : ObjectId("57715f0d08b8f7942c00002b"), 
     "Name" : "Journals", 
     "URLName" : "Journals", 
     "Image" : "http://www.alliedacademies.org/images/accounting.png", 
     "Description" : "Journals and Diaries about Businesses", 
     "NoForums" : 0, 
     "NoTopics" : 0, 
     "NoComments" : 0, 
     "NoUsers" : 0, 
     "CoverImage" : "http://www.advantagebusinessvaluations.com/wp-content/uploads/2015/08/slide3.jpg", 
     "Children" : [] 
    }, 
    { 
     "_id" : ObjectId("57740ae208b8f7f41a000039"), 
     "Name" : "Stock Exchange", 
     "URLName" : "Stock-Exchange", 
     "Image" : "https://38.media.tumblr.com/avatar_bd29383b5657_128.png", 
     "Description" : "Stock Exchange, US Stock", 
     "NoForums" : 0, 
     "NoTopics" : 0, 
     "NoComments" : 0, 
     "NoUsers" : 0, 
     "CoverImage" : "http://c.fastcompany.net/multisite_files/coexist/imagecache/1280/poster/2013/04/1681873-poster-1280-stock-chart.jpg", 
     "Children" : [ 
      { 
       "_id" : ObjectId("5774464608b8f7f41a00004a"), 
       "Name" : "Stock Software", 
       "URLName" : "Stock-Software", 
       "Image" : "http://s1.evcdn.com/images/block/I0-001/026/278/060-2.jpeg_/1-day-introduction-forex-stock-market-trading-60.jpeg", 
       "Description" : "Stock Excba ge Software", 
       "NoForums" : 0, 
       "NoTopics" : 0, 
       "NoComments" : 0, 
       "NoUsers" : 0, 
       "CoverImage" : "http://media.therakyatpost.com/wp-content/uploads/2015/04/stock-exchange-record-bigstock-900x470.jpg", 
       "Children" : [] 
      }, 
      { 
       "_id" : ObjectId("5774e2cb08b8f76c1a00002e"), 
       "Name" : "Meta Trader", 
       "URLName" : "Meta-Trader", 
       "Image" : "http://www.file-extensions.org/imgs/app-icon/128/6904/metatrader-icon.png", 
       "Description" : "MetaTrader", 
       "NoForums" : 0, 
       "NoTopics" : 0, 
       "NoComments" : 0, 
       "NoUsers" : 0, 
       "CoverImage" : "http://www.roboforex.com/files/filemanager/image/site/metatrader.png", 
       "Children" : [] 
      }, 
      { 
       "_id" : ObjectId("5774eb2708b8f76c1a000043"), 
       "Name" : "Meta Trader", 
       "URLName" : "Meta-Trader", 
       "Image" : "http://www.file-extensions.org/imgs/app-icon/128/6904/metatrader-icon.png", 
       "Description" : "MetaTrader", 
       "NoForums" : 0, 
       "NoTopics" : 0, 
       "NoComments" : 0, 
       "NoUsers" : 0, 
       "CoverImage" : "http://www.roboforex.com/files/filemanager/image/site/metatrader.png", 
       "Children" : [] 
      }, 
      { 
       "_id" : ObjectId("5774eb8208b8f76c1a000044"), 
       "Name" : "Meta Trader", 
       "URLName" : "Meta-Trader", 
       "Image" : "http://www.file-extensions.org/imgs/app-icon/128/6904/metatrader-icon.png", 
       "Description" : "MetaTrader", 
       "NoForums" : 0, 
       "NoTopics" : 0, 
       "NoComments" : 0, 
       "NoUsers" : 0, 
       "CoverImage" : "http://www.roboforex.com/files/filemanager/image/site/metatrader.png", 
       "Children" : [] 
      }, 
      { 
       "_id" : ObjectId("5774eb8f08b8f76c1a000045"), 
       "Name" : "Meta Trader", 
       "URLName" : "Meta-Trader", 
       "Image" : "http://www.file-extensions.org/imgs/app-icon/128/6904/metatrader-icon.png", 
       "Description" : "MetaTrader", 
       "NoForums" : 0, 
       "NoTopics" : 0, 
       "NoComments" : 0, 
       "NoUsers" : 0, 
       "CoverImage" : "http://www.roboforex.com/files/filemanager/image/site/metatrader.png", 
       "Children" : [] 
      } 
     ] 
    } 
], 
"URLName" : "Business" 
} 

どのように私はBusiness.Children.Childrenに別の文書を挿入することができます。(株ソフトウェア).Children

答えて

1

は値をプッシュする位置演算子を使用します。

https://docs.mongodb.com/manual/reference/operator/update/positional/

db.collectioname.update(
    { 
    "_id" : ObjectId("576bddaa08b8f7dc20000033"), 
    "Children._id" : ObjectId("57715e0608b8f7441b00002d") 
    }, 
    { 
    $push: 
    {"Children.$.Children": 
    { 
     "Name" : "Business School", 
      "URLName" : "Business-School", 
      "Image" : "http://www.small-business-website.net/wp-content/uploads/2016/04/How-to-achieve-a-successful-business-sale-128x128.jpg", 
      "Description" : "Everything about Business Schools", 
      "NoForums" : 0, 
      "NoTopics" : 0, 
      "NoComments" : 0, 
      "NoUsers" : 0 
     } 
    } 
    } 
    ) 

:モンゴはupdate.Itにネストされた文書を許可しないしない用心は既知の問題です。単一のレベルのみが許可されます。 https://jira.mongodb.org/browse/SERVER-831

関連する問題