i trying update row in (typed) mongodb collection c# driver. when handling data of particular collection of type mongocollection<user>, tend avoid retrieving sensitive data collection (salt, password hash, etc.)
now trying update user instance. however, never retrieved sensitive data in first place, guess data default(byte[]) in retrieved model instance (as far can tell) before apply modifications , submit new data collection.
maybe overseeing trivial in mongodb c# driver how can use mongocollection<t>.save(t item) without updating specific properties such user.passwordhash or user.passwordsalt? should retrieve full record first, update "safe" properties there, , write back? or there fancy option exclude fields update?
thanks in advance
save(somevalue) case want resulting record or become full object (somevalue) passed in.
you can use
var query = query.eq("_id","123"); var sortby = sortby.null; var update = update.inc("logincount",1).set("lastlogin",datetime.utcnow); // update, can chain series of update commands here mongocollection<user>.findandmodify(query,sortby,update); method.
using findandmodify can specify fields in existing record change , leave rest alone.
you can see example here.
the thing need existing record _id, 2 secret fields need not loaded or ever mapped poco object.
Comments
Post a Comment