i've got a query optimization question that i cant quite figure out. It deals with geoLocation and time. I've got a ton of events, that all have a startTime
, endTime
(indexed), and location
(indexed). If i want to get the events that are happening nearby by a certain location that haven't happend yet, i can do one of two ways:
getNearest()
command (which would return all the expired events) and then filter out the events that haven't happend yet. My one worry with this apporach is that getNearest()
specifies how many to return, but I essentially need all of them within the given radius so i don't miss any events that haven't happend yet.Im just unsure how i can figure out the fastest/most effecient query for this.
The best option to me would seem to be to filter and get all events that haven't happend yet, then use getNearest() to take advatage of the indexes. But i can call a get nearest on a filtered set. Please help!?!?!
For getting all events within a radius, I recommend using getIntersecting()
together with r.circle
.
That is not only more efficient than getNearest
, but also doesn't have any limit on the number of returned documents.
You might need to make the radius you pass into r.circle
slightly larger, to account for the fact that the generated polygon will be slightly smaller than the specified radius between the vertices.