if you pass categoryId it will return category with that categoryId but if you don't pass it, I want this route to return all categories... I tried this with $or but it always returns all categories regardless of I passed categoryId or not :
await Category.find({ $or: [{ _id: categoryId }, {}] });
I can use the if statement but it takes a lot of code, can this be done cleaner?
Something like this:
await Category.find({ _id: (categoryId || {$exists: true}) });