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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -