我有一个包含消息的消息集合,模型看起来像这样。
var MessageSchema = new mongoose.Schema({
groupId: { type: Schema.ObjectId, ref: 'Group' },
});
var GroupSchema = new mongoose.Schema({
type: String,
groupMembers: [{ "user": { type: Schema.ObjectId, ref: 'User' } }],
});
这是我的代码:
Message.find({ 'groupId': { $in: groupIds } })
.populate(
{ path: 'groupId', select: 'groupMembers type name level',
populate: { path: 'groupMembers.user', select: 'name _id photo', model: 'User' } })
仅当 groupId.type 与条件匹配时,如何才能填充 groupMembers.user ?
我试过这个但是: - (
{match:"groupId.type":'individual'}