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.