mongoose
mongoose copied to clipboard
.select() doesn't work when chained off a namedScope
var mongoose = module.exports.mongoose = require('mongoose');
var User = new mongoose.Schema({
_type : { 'type': String, 'default': 'user' },
username : { 'type': String, 'index': { unique: true } },
provider_data : {},
lastLogin : Date,
created_at : { 'type': Date, 'default': Date.now }
});
User.namedScope('byId', function(id){
return this.where('_id',id);
});
mongoose.model('User', User);
var UserModel = mongoose.model('User');
UserModel.where('_id','4ec348d44affdbd287000013').select('username','_id').find(function(err,res){
console.log(err,res);
});
UserModel.byId('4ec348d44affdbd287000013').select('username','_id').find(function(err,res){
console.log(err,res);
});
probably the same as #455
closed by 26ed874