I would like to query through the populated field. In this case, the populated field is reviews. So if my searched query matches the reviews tables description field... then return that book. Reviews is an array of objects and description is one of the keys in it.
I have tried using reviews[0].description in the query object but it didn't work.
getBookInfo: (req, res) => {
const search = req.params.search;
const query = { $or: [{ title: { $regex: search, $options: 'i' } }] };
Books.find(query).populate('reviews').exec(function(err, books) {
if (err) {
return err;
}
return books;
});
}