mongo 连表条件查询遇到的问题请教
场景
假设现在我有两张表
表一 user
{
"username": { type: String, index: true },
"userid": { type: String },
"class_info" : { type: Schema.Types.ObjectId, ref: 'class' }
}
表二 class
"classid": { type: String },
"classname": { type: String }
遇到的问题
const result = await this.ctx.model.User
.find({ userid: 123 }, { _id: 0, __v: 0 })
.populate('class', { classname: "高三一班" });
查询出来的结果是
{
userid: 123,
username: 小明,
class_info: []
}