mongo virtual

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];
});

上一篇:Paint the Wall ZOJ - 2747


下一篇:[问题2014S13] 复旦高等代数II(13级)每周一题(第十三教学周)