node.js - Node, Mongoose: Remove json element from query result with delete -
i strange behavior. here's thing: make database query , want delete element of json returned query. doesn't seem work (i.e. element not deleted),
var user=json; delete user.element;
while works
var user={element:json.element,blement:'stuff'} delete user.element;
i think referring json mongoose document object given tags added question. since object attached it's "schema", may have rules in there such "required" field or such interfering operation trying do.
in order raw form of object back, use .toobject()
method on document result:
model.findone({ _id: id}, function(err,doc) { var raw = doc.toobject(); delete raw.element; console.log( raw ); });
of course can omit field being returned in query result basic form provided .select()
:
model.findone({ _id: id}, '-element', function(err,doc) { console.log( doc ); });
either form remove particular field response, if possibly want more control on result can provided field projection .select()
use .toobject()
form , manipulate plain javascript object.
Comments
Post a Comment