javascript - Update specific values in a nested array within mongo through mongoose -
i have following schema(without _id) -
{uid: string, inbox:[{msgid:string, someval:string}] }
now, in request msgid , use in following mongoose query this-
my_model.findone({'inbox.msgid':'msgidvaluexyz'} , function(err, doc) { console.log(doc); return !0; })
now, problem whole document has specific message along other messages in inbox -
output- {uid:'xyz', inbox:[ {msgid:,someval}, {msgid:'our queried msgid',someval}, //required sub array {msgid:,someval}, ] }
now query can use specific sub array document inbox large looped through.
use $
positional selection operator have returned doc include matched inbox
element:
my_model.findone({'inbox.msgid':'msgidvaluexyz'} , {'inbox.$': 1} , function(err, doc) { console.log(doc); return !0; })
Comments
Post a Comment