I have this situation.
There are "store" documents in our database, and sub-documents (many from one) as "branch office".
Each branch office has a location feature, which has been indexed for geolocation search.
Then, the problem is:
{"name": "store1", branch office: [{"name": "b1", "location": [-70.6434137 99, 99, -33.4268697]}, {"name": "b2", "location": [80.4,43.3]}]}}
if I am doing this aggregation :
Store.collection.aggregate ([{"$ geoNear" = & gt; {"Near" => [= 70.64341379999999, -33.4268697], "Distance Field ="> The result is that each branch office, both lines or records, Repeat the distance with the area Only one branch office was found in GeoOir. Thanks to the ret ret geolocation search for the site, shedding sub-documents or sub-documents?
Thanks.
The option below is includeLocs
:
store overall ([{" $ geoNear ": {" near ": [-70.64341379999999, -33.4268697]," distance field ":" distance "," maxdistance ": 0.0900899926955034," addloc " : "Location"}}}))
Output is matched in the output field "Distance "" For "location":
{"_id": ObjectId ("5507b18d1c3bdce0535aecd0"), "name": "Store1", "branch office ": [{" Name ":" b1 "," location ": [-70.6434137 99 99 99, -33.4268697]}, {" name ":" bo 2 "," location ": [80.4, 43.3]} ], "Distance": 0, "location": [-70.64341379999999, -33.4268697]}
If you wanted in a specific sub-document that array was used in full details , You can continue with a filter using the following:
Store.aggregate ([{"$ geoNear": {"$ $ ": {-70.64341379999999, -33.4268697]," Distancefill "" "Distance", "maxdistance": 0.0900899926955034, "included": "location"}}, {"$ redact": {"$ cond": [{"$ Eq": ["$ location", "$$ Originally prior to MongodiBe 2.6: Pre class = "lang-js prettyprint-override"> store. Composite ([["$ geoNear": {"nea R": [-70.64341379999999, -33.4268697], "Distance Field": "Distance", "Maxdistance": 0.0900899926955034, "Include": "Location"}}, {"$ "{$ $"}, {"$ {" $ Match ": [" $ location "," $ branchoffices.location "]}}}, {" $ match ": {" $ match ": {" $ {"$ Match": {"$ match": {"$ match": {{"$ group": {"$ group": {"_id": "$ _id", "name": {" "$ First": "$ name"}, "branch office": {"$ push": "$ Branchoffices"}, "distance": {"$ first" "$ distance"}}}])
/ Pre>
You should be aware that the objects within the sub-document are not always used in an optimum solution and usually have different functions For example, if your data is probably contained in the "multiple" places that are near "point", then only the singular "close" point will be able to match in this way.
When you can do that, it would be best to consider how you are using it and the results you expected. In most cases, location data can be used in its own document. It should be prescribed, but according to the sub-document array here.
No comments:
Post a Comment