I have a list of events. I would like to search both the title
and description
fields for a certain phrase and return events in a given radius matching the query.
I am currently using the $or
operator, which seems to work. However, I am wondering if there is a better way of doing this? I've created a compound text index that uses both fields; I'm just not sure if it actually gets used.
let queryText = /someString/;
return db.collection('events').aggregate([
{
$geoNear: {
near: [lng, lat],
distanceField: 'distance',
maxDistance: radius,
query: {
$or: [
{title: queryText},
{description: queryText}
]
},
spherical: true
}
}
]).toArray();