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];
});
时间: 2024-10-05 08:59:38