猫鼬如何填充和匹配填充的字段

时间:2020-07-20 17:07:24

标签: node.js mongoose filter

我有一个CheckoutSchema,它引用一个Checkin对象,该对象具有我要匹配的属性email。 我想知道我该怎么做。

//CheckinModel file:
const CheckinSchema = new Schema({
    eventId: {
        type: String, 
        required: true,
    },
    email: {
        type: String,
        required: true,
    }
}, { 
    timestamps: true,
});


//CheckoutModel file:
const CheckoutSchema = new Schema({
    checkin: {
        type: Schema.Types.ObjectId,
        ref: 'Checkin',
        required: true,
    },
}, {
    timestamps: true,
});

1 个答案:

答案 0 :(得分:0)

您可以使用

Checkin.find({ email: your_email })
       .populate(checkoutSchema)
       .exec()
       .then(result => {
            })
       .catch(error => {
            })

尝试将您要匹配的传递电子邮件地址作为your_email。 result会在成功时接收,error会在发生错误时接收。

相关问题