好吧,我的行为举止如下:
const User = new mongoose.Schema({
name: String,
...
});
const Tag = new mongoose.Schema({
code: String,
status: {
type: String,
enum: ['LIBERATE','BINDED','INACTIVE']
},
user: {
type: Schema.Types.ObjectId,
ref: 'user'
}
});
const Vehicle = new mongoose.Schema({
name: String,
tag: {
type: Schema.Types.ObjectId,
ref: 'tag'
}
});
我需要在没有相应用户的情况下,不要在此查询之后返回元素:
Vehicle.find()
.populate({
path: 'tag',
match: { status: 'BINDED'},
populate: {
path: 'user',
}
});
状态为BINDED以外的标签将没有相应的用户。但是,在此模型中,我将返回所有标签。
猫鼬5.7.7
MongoDB 4.2.3
节点12.15.0