I got an unexpected result when using $geoWithin
,
I've this:
perim = 10
center = [35.964734, 5.03952]
if i run:
list(db.users.find({"adr.cor":{"$geoWithin":{"$center":[center, perim]}}}))
I get a result that contains further coordinates, for example: [36.743954, 4.365041]
which is further! (at least 400km)
what am i doing bad?
The custom MongoDB CRS uses a counter-clockwise winding order and allows $geoWithin to support queries with a single-ringed GeoJSON polygon whose area is greater than or equal to a single hemisphere. If the specified polygon is smaller than a single hemisphere, the behavior of $geoWithin with the MongoDB CRS is the same as with the default CRS.
Operators in Geospatial for MongoDB can be divided into two parts which are Query Selectors and Geometry Specifiers. We will now understand each of there types, along with queries and examples. The Geometry Specifiers are used with the Query selectors so that we will learn these together.
As such, MongoDB can return $geoWithin queries more quickly than geospatial $near or $nearSphere queries, which sort results. $geoWithin does not guarantee that it will consider a piece of geometry to contain its component geometry, or another polygon sharing its component geometry.
To query with a single-ringed GeoJSON polygon whose area is greater than a single hemisphere, the $geometry expression must specify the custom MongoDB coordinate reference system. For example: Deprecated since version 2.4: $geoWithin replaces $within in MongoDB 2.4.
When using $center:[longitude,latitude], radius, the radius is measured in radians, so you would have to convert 10 radians to km.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With