Take filtering out the password field as an example
1. password:0
User.findOne({username, password: md5(password)}, {password:0}, function (err, user)
{
//处理逻辑
})
2. select:false
Directly when defining the schema rules, it is stipulated that the password will not be returned in the query
var userSchema = new mongoose.Schema({
username: {
type:String,
required:true,
minlength:2,
maxlength:20
},
password: {
type:String,
required:true,
select:false
},
})