我正在尝试进行远程网格使用的查询,因此我将不得不在每个字段上处理sort(asc,desc).
以下是架构:
var customerSchema = new mongoose.Schema({
status: {type: mongoose.Schema.Types.ObjectId, ref: 'Status'},
contact: {type: mongoose.Schema.Types.ObjectId, ref: 'Contact'}
}, { collection: 'Customer' });
customerSchema.virtual('contactName').get(function () {
if (this.contact && this.contact.get) {
return this.contact.get('firstName') + ' ' + this.contact.get('lastName');
}
return '';
});
customerSchema.virtual('statusName').get(function () {
if (this.status && this.status.get) {
return this.status.get('name');
}
return '';
});
customerSchema.set('toJSON', { virtuals: true });
customerSchema.set('toObject', { virtuals: true });
mongoose.model('Customer', customerSchema);
// STATUS
var statusSchema = new mongoose.Schema({}, { collection: 'Status' });
mongoose.model('Status', statusSchema); …Run Code Online (Sandbox Code Playgroud)