Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use geowithin in mongodb?

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?

like image 426
Abdelouahab Pp Avatar asked Jul 01 '13 23:07

Abdelouahab Pp


People also ask

How does $geowithin work with the custom MongoDB CRS?

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.

What are operators in geospatial for MongoDB?

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.

What is the difference between $geowithin and $nearsphere in MongoDB?

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.

How to query a single-ringed GeoJSON polygon in MongoDB?

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.


1 Answers

When using $center:[longitude,latitude], radius, the radius is measured in radians, so you would have to convert 10 radians to km.

like image 173
Kay Avatar answered Sep 21 '22 19:09

Kay