javascript - Best practice to create/update Mongoose objects -
i have multi depth mongoose schemas. when creating/updating assign each provided value json object object field. couple of things. 1 auto remove null values prevent mongoose trying validate them , second not assign each value/field individually pass whole json object , have schema handle validation using - assume if there extra/non existent fields in json object discarded. solution therefore create function recursively walk through json object removing both null values forbidden fields (i.e. created_at, _id, etc) pass rest along , save. have suggestion in mongoose or of there issues not seeing approach?
maybe method want findbyidandupdate
in fact, when use save() method, update field changed:
result.true_name = "test233334";
result.save();
log:mongoose: admins.update({ _id: objectid("51b5af1a370c3fa716000001") }) { '$set': { true_name: 'test233334', updated_at: new date("mon, 10 jun 2013 10:49:38 gmt") } } {}
Comments
Post a Comment