Hi,
I have a collection called reports, which has (among other fields) the following:
_id (of course), incident_date, incident_details, address_string, city, province, country, lat, and lon. I’m trying to find all documents in the collection which match the address_string (and eventually I will match on co-ordinates but that will require some refactoring), so I can find documents that are for the same address as my original. Ideally I would like to exclude the one I’m matching against.
So if my report collection had, say 4 different reports for 123 Fake St. Springfield, OH, all with different dates and details, I would supply the ID for one and get the other 3.
in SQL it would be like this (simplifying to search on just 123 Fake St. for now):
select *A. from A.REPORTS WHERE _ID in (select _ID from REPORTS B where B.ADDRESS_STRING=A.ADDRESS_STRING)
I have a feeling this is probably aggregation pipeline, but not sure how to formulate it.
Currently the only concrete way I can think of doing it is to do something like
db.reports.find({_id: ObjectId(‘myUID’)})
and take the results of that in an object and query again using the address_string
from the first query as a parameter in the second db.reports.find().
That approach feels clumsy and not well suited to nodeJS which is inherently asynchronous.
Thanks in advance
-Hugh
PS. I’m probably going to eventually refine my schema so that I can do geographical searches (i.e. give me all reports within 20 ft of this address).