填充data booking_unique_id
的所有时间一直在给我null
。
以下是架构:
const chat = require('../models/chat.model')
const booking_details = new Schema({
booking_unique_id:{type:Object,ref:chat,field:'chat_screen_id'}
});
const chat_details = new Schema({
...
receiver_public_name:{type:String}
chat_screen_id:{type:Object}
});
Booking.find({booking_status:'e'}).populate('booking_unique_id'))
答案 0 :(得分:0)
ref populate
当前不支持它,猫鼬Issue-3225和Issue-1888中存在问题,
作为替代方案,他们发布了populate-virtuals,
const chat_details = new Schema({
...
receiver_public_name: { type: String }
chat_screen_id: { type: Object }
});
const chat = require('../models/chat.model');
const booking_details = new Schema({
booking_unique_id: { type: Object }
});
booking_details.virtual('bookings', {
ref: chat, // The model to use
localField: 'booking_unique_id', // Find booking where `localField`
foreignField: 'chat_screen_id', // is equal to `foreignField`
// Query options, see /mongoose-query-options
// options: { sort: { name: -1 }, limit: 5 }
});
const Booking = mongoose.model('Booking', booking_details);
Booking.find({ booking_status: 'e' }).populate('bookings').exec(function(error, result) {
console.log(result);
});