[英]Update command in mongoose is removing old sub document
I have the following document in a collection, here address is a sub document 我在集合中有以下文件,这里的地址是子文件
{
name:'Belmont Race',
address:{city:'Brentwood', state:'TN', postal:'35704'}
}
Here is my UPDATE query in mongoose, 这是我的猫鼬的UPDATE查询,
Let where={name:'Belmont Race'};
Let set={$set:{'address.state':'PN'}};
companies.updateMany(where,set, (err,res)=>{
if(err){console.log(err);}
// do something
})
Expected output is, 预期的输出是
{name:'Belmont Race', address:{city:'Brentwood', state:'PN', postal:'35704'}}
But it removing old entire address sub document and giving the output like below 但是它删除了旧的整个地址子文档并给出如下输出
{name:'Belmont Race', address:{ state:'TN' }}
Any Idea? 任何想法?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.