As much as I am glad the solution from Portability 1 works, I am trying to solve it with Portability 2, but can’t get it to work (probably because I don’t understand this async stuff yet).
I defined an async function
const aggregate = async function(collection,aggregation) {
var result = await collection.rawCollection().aggregate(aggregation).toArray();
console.log('aggregate result',result);
return result;
};
which prints out the correct result, but when I call the function
const resultArray = aggregate(MyCollection, theAggregation);
resultArray is a Promise, and I don’t understand why. I am actually trying to use the result of the aggregation in a publication, but can’t get it to work.