Skip to content

Instantly share code, notes, and snippets.

@aheckmann
Created September 23, 2011 02:04
Show Gist options
  • Save aheckmann/1236589 to your computer and use it in GitHub Desktop.
Save aheckmann/1236589 to your computer and use it in GitHub Desktop.
var maSchema = new Schema({
name: { type: String, default: 'nameless' }
, age: { type: Number, default: function () { return 0 }}
});
var M = mongoose.model('M', maSchema);
// populate some data ...
M.findOne({..}, { age: 1 }, function (err, m) {
console.log(m.name) // undefined (previously would be "nameless")
console.log(m.age) // some value
console.log(m._id) // some value
})
M.find({..}, { age: 0 }, function (err, docs) {
var m = docs[0];
console.log(m.name) // some value
console.log(m.age) // undefined (previously would be 0)
console.log(m._id) // some value
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment