- Goal:
Pass an array to a MongoDB aggregation so I can use the array as the value of an $and operator
- Details:
In my JS script I create a variable:
const datesArray = [
{ $gte: { $date: `${selectedYear}-${datesObj.start}` } },
{ $lte: { $date: `${selectedYear}-${datesObj.end}` } },
];
And pass it into my query via
aggregateBrokerCommissionReports.trigger({
additionalScope: {
datesArray
},
onSuccess: (data) => {
resolve(data);
},
});
Then my aggregation attempts to use it as the value of the $and operator
{
$match: {
$and: {{ datesArray }}
}
},
I receive an error because the array is converted into an object with index keys so mongoDB doesn't know what to do with it
How do I force retool to maintain the Array type and not convert my array to an object?