Skip to content

Commit 35ed7c5

Browse files
committed
Add a geo example using $maxDistance.
1 parent d06a48c commit 35ed7c5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

doc/examples/geo.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ Using the geospatial index we can find documents near another point:
5959
"{u'loc': [4, 4], u'_id': ObjectId('...')}"
6060
"{u'loc': [1, 2], u'_id': ObjectId('...')}"
6161

62+
The $maxDistance operator requires the use of :class:`~bson.son.SON`:
63+
64+
.. doctest::
65+
66+
>>> from bson.son import SON
67+
>>> for doc in db.places.find({"loc": SON([("$near", [3, 6]), ("$maxDistance", 100)])}).limit(3):
68+
... repr(doc)
69+
...
70+
"{u'loc': [2, 5], u'_id': ObjectId('...')}"
71+
"{u'loc': [4, 4], u'_id': ObjectId('...')}"
72+
"{u'loc': [1, 2], u'_id': ObjectId('...')}"
73+
6274
It's also possible to query for all items within a given rectangle
6375
(specified by lower-left and upper-right coordinates):
6476

0 commit comments

Comments
 (0)