在创建Schma 时指定对应的collection
var db_url = 'mongodb://localhost:27017/test';
var db = mongoose.connect(db_url);
db.connection.on('error', function (error) {
console.log('数据库连接失败:' + error);
});
db.connection.on('open', function () {
console.log('——数据库连接成功!——');
});
var Schema = mongoose.Schema;
var userSchema = new Schema({
name : { type:String }
},{ collection: "person"});
var userModel = mongoose.model("usertest", userSchema);
userModel.find({'name':'winyh1'}).select('_id email').exec(function (err, users){
if (!err){
console.log(users);
}
});