mongodb - Updating an element in an array after limiting the fields to the client -


let's have player collection , when in context of game, limits games array include game.

meteor.publish('gameplayer', function (playerid, gameid) {   check(playerid, string);   check(gameid, string);    if (roles.userisinrole(this.userid, roles.getallroles().fetch(), gameid)) {     return players.find({       _id: playerid,       games: {         $elemmatch: {           id: gameid         }       }     }, {       fields: {         "games.$": 1       }     });   } }); 

now structure expecting on client.

// server > players.findone({ _id: "123456" }); {   _id: "123456",   battletag: "corvid#1234",   games: [{     id: "5678",     name: "starcraft ii",     class: "zerg",     ladder: 23   }, {     id: "1234",     name: "world of warcraft",     class: "shaman",     ladder: 123   }] }  // client > var params = router.current().params; > meteor.subscribe('gameplayer', params.gameid, params.playerid); > players.findone(); {   _id: "123456",   battletag: "corvid#1234",   games: [{     id: "5678",     name: "starcraft ii",     class: "zerg",     ladder: 23   }] } 

what confused how update array of objects when have limited results fed in reliable way. want change limited field's class protoss, example.

how update array of objects safely on client in meteor when fields limited?

there no issue long update correct games.id.

players.update(   {     _id: "123456",      "games.id": 5678   },    {     $set: {        "games.$.class" : "protoss"      }   } ) 

the client simulate update on minimongo while real update done on server. whatever changes on server propagated client.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -