Hi @Abdulrahman_almuhajir,

Since your code is JavaScript, I assume you are using Mongoose as a client.

I assume that collectionId is a reference to a document in another collection (ObjectId).

When you perform a find() query, Mongoose will automatically convert your string to ObjectId.

However, when you perform aggregate() query, you need to cast your string yourself, in order for the query to work.

So, I suggest that you try the following:

const { ObjectId } = require('mongoose').Types;

...

cards = await Card.aggregate([
  {
    $match: { collectionId: ObjectId(collectionId) },
  },
]);
2 Likes