我遵循了Mongoose Schema
var UserSchema = mongoose.Schema({
createdOn: {type: Date, default:Date.now },
purchaseDate:Date,
expiryDate:Date,
isEnabled: {type: Boolean,default: true},
messages:[{
message: String,
location: String,
date: Date,
}]
});
当我将文档转换为JSON时,我想删除messages数组中每条消息的_id
。我目前的toJSON方法在
UserScheme.methods.toJSON = function() {
var obj = this.toObject();
delete obj._id;
delete obj.__v;
return obj;
};