Mongodb C# driver update array element -
i can't seem figure out exact set of statements needed update entire element of array. have currently:
//id, gameid, updatedgame passed in var client = mongocontext.clients.findone( query<client>.eq(x => x.id, id)); var index = client.games.findindex(x => x.id == gamedid); var update = update<client>.set(x => x.games[index], updatedgame); var query = query<client>.eq(x => x.id, client.id); mongocontext.clients.update(query, update); mongocontext.clients.save(client); i can in javascript, unfortunately i'm working in c# @ moment. help.
the update() statement using more suited bulk updates. in case need update 1 record need save() function. also, without knowing code behind mongocontext there things can with. object looks adopted mixture between ef code first , mongo syntax. anyway, here how i've accomplished simular:
mongocollection<reported> collection = getcollection(); reported report = collection.findonebyid(id); report.isreviewed = true; collection.save(report); by using findonebyid() function mongo returns copy of object it's objectid. means subsequent changes object updated when pass save() function. in case, changing array value done in set report.isreviewed = true;
Comments
Post a Comment