//user.js var mongodb = require(‘…/config/mongodb’); var Schema = mongodb.mongoose.Schema; var ObjectId = Schema.ObjectId; var UserSchema = new Schema({ id : ObjectId, name : String, email : String }); UserSchema.methods.findOneByName = function(name, callback) { this.findOne({name : name}, callback); }; module.exports = mongodb.mongoose.model('users’, UserSchema);
//index.js var UserModel = require(“./user”); var new_user_entity=new UserModel({}); //here 这里怎么不能用这个方法呢~ ~是不是定义错了啊,求救!0.0 new_user_entity.findOneByName("zhangsan",function(err,doc){ if(err){ … }else{ … } });