使用Mongoose-paginate插件填充多个Mongoose模型字段

我有一个Mongoose模式(约会)与两个参考字段(发件人和接收器)。 两个引用相同的架构(用户)。 我正在尝试使用mongoose-paginate插件来填充这两个字段。

约会架构片段。

var paginate = require('mongoose-paginate'); var AppointmentSchema = new Schema({ dateCreated: {type: Date, default: Date.now}, sender: {type: ObjectId, ref: 'User'}, receiver: {type: ObjectId, ref: 'User'}, message: String, ......................... AppointmentSchema.plugin(paginate); var Appointment = mongoose.model('Appointment', AppointmentSchema); module.exports = Appointment; 

用户架构片段。

 var UserSchema = new Schema({ username: String, name: { first: String, middle: String, last: String }, .................. var User = mongoose.model('User', UserSchema); module.exports = User; 

mongoose分页查询。

 Appointment.paginate({}, request.query.page, request.query.limit, function(error, pageCount, appointments, itemCount) { if (error) { return console.log('ERRRRRRRRRR'.red); } else { console.log(appointments); return response.render('message/inbox', { pageTitle: "Trash", messages: appointments, pageCount: pageCount, itemCount: itemCount, currentPage: currentPage }); } }, {columns: {}, populate: 'receiver', populate: 'sender', sortBy: {title: -1}}); 

这工作正常,但我想填充发件人和收件人字段。 请我怎么去那个。 我尝试通过在JSON领域,但没有工作。

       

网上收集的解决方案 "使用Mongoose-paginate插件填充多个Mongoose模型字段"

我只是通过一个字段数组来填充 ,它的工作就像一个魅力。

 Appointment.paginate({}, request.query.page, request.query.limit, function(error, pageCount, appointments, itemCount) { if (error) { return console.log('ERRRRRRRRRR'.red); } else { console.log(appointments); return response.render('message/inbox', { pageTitle: "Trash", messages: appointments, pageCount: pageCount, itemCount: itemCount, currentPage: currentPage }); } }, {columns: {}, populate: ['receiver', 'sender'], sortBy: {title: -1}});