3
我有这个模式猫鼬 - 排序数组长度
var PostSchema = new Schema({
title: {type: String, trim: true}
, description: {type: String, trim: true}
, votes: [{ type: Schema.ObjectId, ref: 'User' }]
})
我想基于票数即职位排序,我需要通过数组的长度进行排序。
试图以通常的方式,但din't工作
PostSchema.statics.trending = function (cb) {
return this.find().sort('votes', -1).limit(5).exec(cb)
}
任何帮助吗?
版猫鼬我使用的是2.7.2