Mongoose学习(2)
1、Schema的扩展
UserSchema.methods.findUserName = function(cb){
return this.model('user').find({username:this.username},cb);
}
var UserModel = mongoose.model('user',UserSchema);
var lsg = new UserSchema({username:{$regex: 'lsg',
$options: 'ig'}});
//$options i就模糊查询,g 忽略大小写
lsg.findUserName(function(err,users){
});
更多regex可以查看官方资料 https://docs.mongodb.com/manual/reference/operator/query/regex/
浙公网安备 33010602011771号