用mongodb更新一个复杂的对象

我有一个像这样的Json对象。

/* 1 */ { "_id" : ObjectId("553e4b0a903fd38019ac2a6a"), "id" : 19, "monday" : { "entrees" : [], "viandes" : [], "legumes" : [], "fromages" : [], "desserts" : [] }, "thursday" : { "entrees" : [], "viandes" : [], "legumes" : [], "fromages" : [], "desserts" : [] }, "wednesday" : { "entrees" : [], "viandes" : [], "legumes" : [], "fromages" : [], "desserts" : [] }, "tuesday" : { "entrees" : [], "viandes" : [], "legumes" : [], "fromages" : [], "desserts" : [] }, "friday" : { "entrees" : [], "viandes" : [], "legumes" : [], "fromages" : [], "desserts" : [] } } 

我想更新这个对象,在数组中插入值。

我testing了不同的查询,但我的对象从来没有更新。

例如,这个查询不能正常工作。

 self.menucollection.update( { 'id' : id }, { $set:{ 'monday':{ 'entrees' : 'toot' } } }, function(err, item){ callback(err, item); } ); 

有任何想法吗 ?

要添加到数组中,您必须使用$push

此外,使用点符号访问星期一/主菜。

 self.menucollection.update({'id': id}, { $push: { 'monday.entrees': 'toot' }});