鉴于以下文件:
{
"_id" : ObjectId("588d121dc23324935a061108"),
"game" : "/donut_fun",
"__v" : 0,
"rooms" : [
{
"members" : [ ],
"timestamp" : 1485640221059,
"roomname" : "fun times"
}
]
}
如何使用game
通过roomname
和findOneAndUpdate()
属性进行查询,并将对象推送到members
数组中。
我在尝试(没有成功):
var player = {pid: 1234, pname: 'Fred'};
var query = {game: '/donut_fun', roomname: 'fun times'};
var update = {$push: {'rooms.$.members':player }};
GamesModel.findOneAndUpdate(query, update, {new: true, upsert:true}, function(err, doc){
console.log(doc);
});