mongoose icon indicating copy to clipboard operation
mongoose copied to clipboard

.select() doesn't work when chained off a namedScope

Open pennyfx opened this issue 14 years ago • 2 comments


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);
});

pennyfx avatar Dec 11 '11 05:12 pennyfx

probably the same as #455

aheckmann avatar Dec 12 '11 15:12 aheckmann

closed by 26ed874

aheckmann avatar Jul 29 '13 22:07 aheckmann