node.js - Complicated nested request in MongoDB -


i have collection documents of format:

{         "_id" : objectid("51b1e27e31b1f4fe0700001b"),         "proposals" : [                 {                         "id" : 17,                         "type" : "question",                         "fr" : {nothing useful},                         "en" : {nothing useful},                         "vote_count" : 0,                         "validate" : 0,                         "username" : "username",                         "voters" : [ ],                         "creationdate" : isodate("2013-07-25t08:32:40.328z")                 },                  {other proposals of same type}          ] }, {same format} 

i'm trying update proposal matched id receive, in right parent. have found a request on mongo cookbook used successfully, on less complicated data format, , can't make works now. here is.

client.collection('games').update({_id: gameid, 'proposals.id': eventid, 'proposals.voters': {'$ne': user}}, {'$push': {'proposals.voters': user}, '$inc': {'proposals.vote_count': 1}, '$set': {'proposals.validate': 1}}); 

gameid , eventid in right format. if use query part of update in find(), right game. i'm struggling see why document isn't updated.

you must $ operator identify position in array want update. update command be:

client.collection('games') .update(      {         _id: gameid,          'proposals.id': eventid,          'proposals.voters': {'$ne': user}     },      {         '$push': {'proposals.$.voters': user},         '$inc': {'proposals.$.vote_count': vote},          '$set': {'proposals.$.validate': 1}     } ); 

Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -