Hello everyone,
I am encountering an issue where an aggregation query is returning an empty array, even though I expect it to return matching documents from my collection. Here’s the relevant portion of my code:
if (useShuffle) {
cards = await Card.aggregate([
{
$match: { collectionId: collectionId },
},
]);
}
- When running the code, I receive an empty array, even though there are documents with this collectionId in the database.
I have verified that the value of collectionId is correct and matches the documents in the collection. However, the aggregation still returns an empty array. When I use a regular find query, it works fine:
const cards = await Card.find({ collectionId: collectionId });
What could be causing this issue? Any insights would be greatly appreciated!
Thank you in advance.