0
修改子文档我有一个猫鼬这样的查询:只选择从蒙戈
var query = Events.findOneAndUpdate({ '_id': event._id,'participants._id':participant._id},{'$set': {'participants.$': participant}}, {upsert:false,new: true},function(err,result){
if(err){
return res.status(500).jsonp({
error: 'Unable to update participant'
});
}
console.log(result.participants[0]);
res.jsonp(result.participants[0]);
});
和查询工作正常修改参与者子文档内的事件集合。
问题:
我只需要修改的参与者将返回JSON和我不是需要整个参与者阵列的,但我不能做到这一点,因为我让所有的参与者时,我做console.log(result.participants);
如何在查询后只获取修改后的子文档?
感谢。看起来这是唯一的方法(尽管它没有效率循环)。 –