Skip to content

Instantly share code, notes, and snippets.

@mcoolin
Forked from aheckmann/goose-2.2.0.js
Created September 24, 2011 05:48
Show Gist options
  • Save mcoolin/1239022 to your computer and use it in GitHub Desktop.
Save mcoolin/1239022 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