The following code works with no querystrings or one querystring only. In other words, simply going to /characters
returns all
I am using destructing of objects for this task.
const filter = req.query.filter ? { _id: { $in: req.query.filter.split(',') } } : {};
const category = req.query.category ? { category: req.query.category } : {};
// more variables that you need and are empty objects if don't exist
const all = await Post.find({ ...filter, ...category }).exec();