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,
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?