I'm trying to builda criteria that would filter the entries in the DB ,yet i'm not getting the proper results when filtering the genre. (the text seems to work but i'm not sure if the code will support both filters).
This is my buildCriteria function, console logging returns the proper values.
function _buildCriteria(filterBy) {
const criteria = {};
const { text, genre } = filterBy;
console.log('genre:', genre);
if (text) {
const txtCriteria = { $regex: text, $options: 'i' };
criteria.name = txtCriteria;
}
if (genre) {
criteria.genre = { $eq: genre };
}
return criteria;
}
This is the query function :
async function query(filterBy) {
try {
const criteria = _buildCriteria(filterBy);
const collection = await dbService.getCollection('tab');
const tabs = await collection.find(criteria).toArray();
return tabs;
} catch (err) {
logger.error('Can not find tabs', err);
throw err;
}
}
Would appreciate your help greatly!