首页 > 解决方案 > 如何根据ref _Id mongoose在第二个文档中的条件在一个文档中查找

问题描述

例如

RecordSchema = {
user:{
   type: Schema.Types.ObjectId,
    ref: 'User'
}
transcations:[Object]
title:String
} 

UserSchema:{
name:String,
active:Boolean
}

我想找到用户活跃的所有记录

例如

records = await Record.find({title:req.query.title}).populate('user).where(
user.active, true);

标签: mongoosemongoose-schemamongoose-populate

解决方案


推荐阅读