How can i retrive all the documents that match my cretria?

Hey there! I’m trying to get all the documents that match the queries. With the following query, I’m getting all the documents, not those that only match. So what’s wrong?

By the way, the current result is an empty array.

Thanks For your help!

1 Like

You are using Mongoose. Mongoose will not automatically convert strings to ObjectIds in aggregation queries, so you need to manually cast the string to the ObjectId:

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


  $match: {
    _id: ObjectId(brandId)

Still, const products is an empty array.