var options={"upsert":false,"multi":false,‘new‘:false}; 不存是否插入,更新是否批量,返回内容是更新前还是后.
permissions.findOne(query, function (err, data) {
if (err) return next(err);
res.json(data);
});
var PersonSchema = new Schema({
name:{
first:String,
last:String
}
});
var PersonModel = mongoose.model(‘Person‘,PersonSchema);
PersonSchema.virtual(‘name.full‘).get(function(){
return this.name.first + ‘ ‘ + this.name.last;
});
PersonSchema.virtual(‘name.full‘).set(function(name){
var split = name.split(‘ ‘);
this.name.first = split[0];
this.name.last = split[1];
});
原文:http://www.cnblogs.com/jayruan/p/6010272.html