Right now I have the following MongoDB query through Mongoose:
var g = new RegExp(search, 'i');
var query = { $or: [ {Tit: g}, {Resumen: g} ] };
Book.find(query).exec((err, books) => {
if(err) {
res.status(500).send({message: "Error en la petición"});
} else {
res.status(200).send({books});
}
});
The query allows me to obtain the books that contain in the title or summary the string stored in query. I would like to be able to sort them so that the results would appear first where the string was in the title and then those that only appeared in the summary.