0

I am new to MongoDB and wanted to create a view after making all the aggregation stages and it seems to give me this error when I click on create view : A pipeline stage specification object must contain exactly one field.

This is the Aggregation query generated by MongoDB Compass :

[{
    $unwind: {
        path: "$destinations",
        preserveNullAndEmptyArrays: true
    }
}, {
    $set: {
        "destinationId": {
            $toInt: "$destinations.ref"
        }
    }
}, {
    $lookup: {
        from: 'destinations',
        localField: 'destinationId',
        foreignField: 'destinationId',
        as: 'destination'
    }
}, {
    $group: {
        _id: "$productCode",
        destinations: {
            "$push": {
                $first: "$destination"
            }
        },
        status: {
            "$first": "$status"
        },
        productCode: {
            "$first": "$productCode"
        },
        language: {
            "$first": "$language"
        },
        createdAt: {
            "$first": "$createdAt"
        },
        lastUpdatedAt: {
            "$first": "$lastUpdatedAt"
        },
        title: {
            "$first": "$title"
        },
        ticketInfo: {
            "$first": "$ticketInfo"
        },
        pricingInfo: {
            "$first": "$pricingInfo"
        },
        images: {
            "$first": "$images"
        },
        logistics: {
            "$first": "$logistics"
        },
        timeZone: {
            "$first": "$timeZone"
        },
        description: {
            "$first": "$description"
        },
        inclusions: {
            "$first": "$inclusions"
        },
        exclusions: {
            "$first": "$exclusions"
        },
        additionalInfo: {
            "$first": "$additionalInfo"
        },
        cancellationPolicy: {
            "$first": "$cancellationPolicy"
        },
        bookingConfirmationSettings: {
            "$first": "$bookingConfirmationSettings"
        },
        bookingRequirements: {
            "$first": "$bookingRequirements"
        },
        languageGuides: {
            "$first": "$languageGuides"
        },
        bookingQuestions: {
            "$first": "$bookingQuestions"
        },
        tags: {
            "$first": "$tags"
        },
        itinerary: {
            "$first": "$itinerary"
        },
        translationInfo: {
            "$first": "$translationInfo"
        },
        supplier: {
            "$first": "$supplier"
        }
    }
}, {
    $lookup: {
        from: 'schedules',
        localField: 'productCode',
        foreignField: 'productCode',
        as: 'schedules'
    }
}, {
    $set: {
        "schedules": {
            "$first": "$schedules"
        }
    }
}, {
    $project: {
        _id: true,
        destinations: true,
        schedules: true,
        status: true,
        productCode: true,
        language: true,
        createdAt: true,
        lastUpdatedAt: true,
        title: true,
        ticketInfo: true,
        pricingInfo: true,
        images: true,
        logistics: true,
        timeZone: true,
        description: true,
        inclusions: true,
        exclusions: true,
        additionalInfo: true,
        cancellationPolicy: true,
        bookingConfirmationSettings: true,
        bookingRequirements: true,
        languageGuides: true,
        bookingQuestions: true,
        tags: true,
        itinerary: true,
        translationInfo: true,
        supplier: true
    }
}
}]

I want to know I am not able to create the view and what the error really means. I checked in multiple places but no luck.

Please help.

Thank you.

  • you can refer this link: https://stackoverflow.com/questions/42232375/mongodb-aggregation-error-pipeline-stage-specification-object-must-contain-exa – Kavita Jain May 18 '21 at 09:11
  • From the `mongo` shell, there isn't any error creating the view. – prasad_ May 18 '21 at 09:23
  • Thanks @KavitaJain , In fact I actually referred that answer, but it doesn't solve my problem. – Vijay Jindal May 18 '21 at 09:24
  • Thank you @prasad_ , I hadn't tried creating the view with Mongo Shell. I just tried that and it works. Thank you, this helped. Probably some issue with MongoDB Compass, I assume. – Vijay Jindal May 18 '21 at 09:28

0 Answers0