mongoose - Mongodb : array element projection with findOneAndUpdate doesn't work? -


i using mongoose , i'm trying update array element , updated. document structure :

{   name:string,     friends:[         {   name:string,             age:number         }     ] } 

when execute following query friends in result want 25 year old friends :

thecollection.findoneandupdate(     {   name : 'cherif',         'friends.name':'kevin'     },     {   $set:{             'friends.$.age':25         }     },     {   friends:         {   $elemmatch:             {   age : 25 }          }     },     function(err,result){         if (!err) {             console.log(result);         }}); 

as the docs findoneandupdate specify, need include projection object select property of options parameter:

thecollection.findoneandupdate(     {   name : 'cherif',         'friends.name':'kevin'     },     {   $set:{             'friends.$.age':25         }     },     {   select: {              friends: {                $elemmatch:                 {   age : 25 }              }         }     },     function(err,result){         if (!err) {             console.log(result);         }     }); 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -