node.js - How to update a specific subdocument with mongoose. (3 levels deep) -


i have following document scheme

var restsschema = new schema({     name: string,     phonenumber: string,     menu: mongoose.schema.types.mixed }); 

and actual simplified document looks like:

{     name: "dominos pizza"     phonenumber: "1800800800"     menu:{              "1":{                   name: "plain pizza",                   soldcounter: 0                },              "2":{                   name: "pizza vegetables",                   soldcounter: 0                 }          } } 

my question how can update specific soldcounter without saving entire document.

i guess need change scheme definition. * i'm new mongoose , mongodb. gentle ;)

with dot notation.

db.collection.update({_id: objectid("...")}, {$set: {"menu.1.soldcounter": 1}}); 

or

db.collection.update({_id: objectid("...")}, {$inc: {"menu.1.soldcounter": 1}}) 

Comments