0
我能够使用$ addToSet更新文档内的数组,但我想更新文档数组内的数组。MONGODB:更新子文档中的嵌套数组
我的架构:
const mySchema1 = new Schema({
myId : {type:String, unique:true},
name : String,
entries : [{
value : String,
keywords:[String]
}]
});
routes.js
app.put('/api/entity',function(req,res){
let model = new Entity();
console.log(req.body);
model.collection.update({"myId":req.body.myId,"entries":req.body.entries},{$addToSet:{"entries":{$each:[req.body.entries]}}},function(err,entries){
if(err){
res.send(err);
}else{
res.send(entries);
}
})
});
现在我想更新(如果存在)/插入(如果不存在), 1.价值 2。特定值的关键字
在此先感谢!
https://stackoverflow.com/questions/23470658/mongodb-upsert-sub-document这可能与您的问题有关 – Sridhar