Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MongoDB中pepiline$unwind合计的性能下降?_Mongodb_Mongoose_Aggregation Framework - Fatal编程技术网

MongoDB中pepiline$unwind合计的性能下降?

MongoDB中pepiline$unwind合计的性能下降?,mongodb,mongoose,aggregation-framework,Mongodb,Mongoose,Aggregation Framework,我有点害怕在同一个查询中多次使用$unwind。 我曾经做过长时间的搜索,因为我只想去银行一次,带上我想要的一切 我的问题是,当我有多个数据时,这将如何保持 以下是查询: Course .aggregate([ { $match: {_id: ObjectId(req.body.CourseId), 'grids.isActive': true} }, { $lookup: { 'from': 'modalities

我有点害怕在同一个查询中多次使用$unwind。 我曾经做过长时间的搜索,因为我只想去银行一次,带上我想要的一切

我的问题是,当我有多个数据时,这将如何保持

以下是查询:

Course
.aggregate([
    {
        $match: {_id: ObjectId(req.body.CourseId), 'grids.isActive': true}
    },
    {
        $lookup: {
            'from': 'modalities',
            'localField': 'ModalityId',
            'foreignField': '_id',
            'as': 'modality'
        }
    },
    {
        $lookup: {
            'from': 'prices',
            'localField': 'PriceId',
            'foreignField': '_id',
            'as': 'price'
        }
    },
    {
        $lookup: {
            'from': 'prices',
            'localField': 'TaxEnrollmentId',
            'foreignField': '_id',
            'as': 'taxEnrollment'
        }
    },
    {$unwind: "$price"},
    {$unwind: "$price.plains"},
    {$match: {"price.plains.parcels": req.body.courseParcels}},
    {$unwind: {
        "path": "$price.promotions",
        "preserveNullAndEmptyArrays": true
    }},
    {
        $match: {$or: [
            {
                "price.promotions.startsAt" : {$lte: new Date},
                "price.promotions.expiresAt": {$gte: new Date},
            },
            {"price.promotions": null}
        ]}
    },
    {$unwind: {
        "path": "$price.promotions.plains",
        "preserveNullAndEmptyArrays": true
    }},
    {$unwind: "$taxEnrollment"},
    {$unwind: "$taxEnrollment.plains"},
    {$match: {"taxEnrollment.plains.parcels": req.body.enrollmentParcels}},
    {$unwind: {
        "path": "$taxEnrollment.promotions",
        "preserveNullAndEmptyArrays": true
    }},
    {
        $match: {$or: [
            {
                "taxEnrollment.promotions.startsAt" : {$lte: new Date},
                "taxEnrollment.promotions.expiresAt": {$gte: new Date},
            },
            {"taxEnrollment.promotions": null}
        ]}
    },
    {$unwind: {
        "path": "$taxEnrollment.promotions.plains",
        "preserveNullAndEmptyArrays": true
    }},
    {$match: {$or:[
        {"price.promotions.plains.parcels": req.body.courseParcels},
        {"price.promotions": null}
    ]}},
    {$unwind: "$modality"},
    {$unwind: "$grids"},
    {$unwind: "$grids.disciplines"},
    {
        $group: {
            _id        : {
                promotion   : "$price.promotions.plains",
                priceDefault: "$price.plains",
                taxEnrollment: "$taxEnrollment",
                modality    : {
                    _id      : "$modality._id",
                    name     : "$modality.name",
                    pillars  : "$modality.settings.pillars",
                    documents: "$modality.settings.rules.documents"
                }
            },
            disciplines: {$addToSet: "$grids.disciplines.DisciplineId"},
        },
    },
    {$unwind: '$disciplines'},
    {
        $lookup: {
            'from'        : 'disciplines',
            'localField'  : 'disciplines',
            'foreignField': '_id',
            'as'          : 'discipline'
        }
    },
    {$unwind: '$discipline'},
    {$unwind: '$discipline.evaluates'},
    {
        $group: {
            _id  : "$_id",
            tests: {
                $addToSet: {
                    $cond: {
                        if  : {$eq: ["$discipline.evaluates.isActive", true]},
                        then: "$discipline.evaluates._id",
                        else: false
                    }
                }
            }
        }
    },
])

我的Mongo是3.4我的Mongo是3.4