首页 > 解决方案 > 猫鼬中的交叉表查询

问题描述

我有 2 个架构teamSchema teamAllocationSchema这里 teamAllocationSchema指的是teamSchema.

我想从中获取所有记录teamAllocationSchema,其中所有记录team_id都有真实的文档teamSchema

无法弄清楚如何为此创建聚合管道,请帮助。

  const teamSchema = new Schema({
    project_id: {

    },
    team_name: {
        type: String,
        required: [true]
    },
    description: {
        type: String
    },
    status: {
        type: Boolean
    }
}, { timestamps: true });

const teamAllocationSchema = new Schema({
    project_id: {
        type: Schema.ObjectId,
        ref: projectModel
    },
    team_id: {
        type: Schema.ObjectId,
        ref: teamSchema
    },
    member_id: [{ type: ObjectId, ref: userModel }],
}, { timestamps: true

标签: node.jsmongodbmongoose

解决方案


推荐阅读