c# - Returning nearest document grouped by field in MongoDB using GeoNear -
i'm using official c# driver query collection in mongodb using geonear.
the documents this:-
{ "_id" : "1" , "resource" : { "_id" : "9", "type" : "aaa" }, "site" : { "_id" : "4123" , "location" : { "longitude" : 145.012345, "latitude" : -30.012345 } } }
there multiple combinations of resources , sites in many-to-many scenario.
i have geonear working ok, need filter results on other criteria.
i have basics working, can example return of particular resource type, need query return closest document each resource type. example if have 10 resource types , several hundred sites (potentially thousands of combinations/documents), query return @ 10 documents... 1 each of resource types, showing closest site each (the query may in fact return less that, if there no sites resource type within maxdistance have specified query)
edit
as using c# library, able work around using linq filter results, i'm still interested in seeing if there way natively in mongodb without relying on implementation.
i suspect mapreduce results achieve want, can't see how in-line geonear command, , i'd rather avoid 2 step process using intermediary collection (caching these results irrelevant in instance query called different source location)
when using geo queries can tell mongodb return n closest results, , can tell mongodb check additional field (like "type" field).
but far know can't tell return closest match each different value of additional field. if find way issue such query using mongodb shell can translate c#.
i think need repeat query once each "type", , if interested in closest match set limit of documents return 1.
Comments
Post a Comment