我有以下模型
var fieldsSchema = new Schema({
name: String,
type: String,
value: String,
media: [{ type: Schema.Types.ObjectId, ref: 'Upload' }],
required: Boolean,
recepientvisible: Boolean
})
var orderSchema = new Schema({
number: String,
date: Number,
updated: Number,
type: { type: Schema.Types.ObjectId, ref: 'OrderTemplate' },
currentstatus: String,
comment: String,
assignedTo: { type: Schema.Types.ObjectId, ref: 'User' },
createdBy: { type: Schema.Types.ObjectId, ref: 'User' },
statuses: [{
name: String,
fields: [fieldsSchema]
}]
});
var Order = mongoose.model('Order', orderSchema);
module.exports = Order;
我做了以下请求
app.post('/order/', function (req, res) {
Order.find()
.populate({ path:'type', select: 'name -_id'})
.populate({ path:'assignedTo', select: 'name -_id'})
.populate({ path:'createdBy', select: 'name -_id'})
.populate({ path:'statuses', populate: { path: 'fields', populate: { path: 'media'} }})
.exec(function (err, orders) {
if (err) throw err;
res.send(orders)
});
})
我需要的是填充媒体字段。但作为回应,我只得到_id
的数组。
所有其他字段填充良好。
如何正确填充媒体字段?