LearnBoost/mongoose — Issue #726: Setting default schema option breaks fields returned by find operation
Author: davidfooks
Created: 2012-02-08 18:13:58+00:00
State: open

Repo:

1. Create a schema key with options
'someDate': {
'type': Date,
'default': Date.now
},
2. Do a find on the model with the fields set to {'_id': false, 'somethingElse': true} e.g.
Cars.find({'_id': carId}, {'_id': false, 'horsepower': true}, foundCar);

Observe: The result of the find operation incorrectly contains the 'someDate' key.

Expected result: The result should only contain the 'somethingElse' key.

If I remove the default property and just set:

'someDate': Date

Then everything acts as expected. Weirdly, deleting the key from the result doesn't work! So if I do this with the result:

console.log(findResult);
delete findResult.someDate;
console.log(findResult);

Then the result isn't deleted! Its there in both logs!