以过滤掉password字段为例
1. password:0
User.findOne({username, password: md5(password)}, {password:0}, function (err, user)
{
//处理逻辑
})
2. select:false
直接在定义schema规则的时候就规定查询的时候不返回password
var userSchema = new mongoose.Schema({
username: {
type:String,
required:true,
minlength:2,
maxlength:20
},
password: {
type:String,
required:true,
select:false
},
})