I am having trouble with something that should be patently obvious. I cant seem to be able to delete properties of my object in node. This is in coffeescript, but I don't think that is relevant.
console.log doc
delete doc.password
console.log doc
Returns:
{ firstname: 'Andrew',
lastname: 'Plummer',
email: 'andrew@stackoverflow...',
password: 'blahblah',
_id: 5014c0a6af36bdaf03000001,
comments: [],
posts: [] }
{ firstname: 'Andrew',
lastname: 'Plummer',
email: 'andrew@stackoverflow...',
password: 'blahblah',
_id: 5014c0a6af36bdaf03000001,
comments: [],
posts: [] }
For something so seemingly obvious I have actually searched around stackoverflow and googled for about half an hour. Sorry if still i have missed a duplicate.
The answer as given by Frédéric in the comment ( so i cant mark it as true) is that my object needed to be explicitly turned into a new object as it had its delete disabled. This is the case with mongoose ODM models in node.