~ubuntu-branches/ubuntu/wily/pymongo/wily-proposed

« back to all changes in this revision

Viewing changes to doc/examples/geo.rst

  • Committer: Package Import Robot
  • Author(s): Federico Ceratto
  • Date: 2015-04-26 22:43:13 UTC
  • mfrom: (24.1.5 sid)
  • Revision ID: package-import@ubuntu.com-20150426224313-0hga2jphvf0rrmfe
Tags: 3.0.1-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
This example shows how to create and use a :data:`~pymongo.GEO2D`
11
11
index in PyMongo.
12
12
 
13
 
.. note:: 2D indexes require server version **>= 1.3.4**. Support for
14
 
   2D indexes also requires PyMongo version **>= 1.5.1**.
15
 
 
16
13
.. mongodoc:: geo
17
14
 
18
15
Creating a Geospatial Index
36
33
 
37
34
.. doctest::
38
35
 
39
 
  >>> db.places.insert({"loc": [2, 5]})
40
 
  ObjectId('...')
41
 
  >>> db.places.insert({"loc": [30, 5]})
42
 
  ObjectId('...')
43
 
  >>> db.places.insert({"loc": [1, 2]})
44
 
  ObjectId('...')
45
 
  >>> db.places.insert({"loc": [4, 4]})
46
 
  ObjectId('...')
 
36
  >>> result = db.places.insert_many([{"loc": [2, 5]},
 
37
  ...                                 {"loc": [30, 5]},
 
38
  ...                                 {"loc": [1, 2]},
 
39
  ...                                 {"loc": [4, 4]}])
 
40
  >>> result.inserted_ids
 
41
  [ObjectId('...'), ObjectId('...'), ObjectId('...'), ObjectId('...')]
47
42
 
48
43
Querying
49
44
--------
79
74
  >>> for doc in db.places.find({"loc": {"$within": {"$box": [[2, 2], [5, 6]]}}}):
80
75
  ...   repr(doc)
81
76
  ...
 
77
  "{u'loc': [2, 5], u'_id': ObjectId('...')}"
82
78
  "{u'loc': [4, 4], u'_id': ObjectId('...')}"
83
 
  "{u'loc': [2, 5], u'_id': ObjectId('...')}"
84
79
 
85
80
Or circle (specified by center point and radius):
86
81
 
90
85
  ...   repr(doc)
91
86
  ...
92
87
  "{u'loc': [1, 2], u'_id': ObjectId('...')}"
 
88
  "{u'loc': [2, 5], u'_id': ObjectId('...')}"
93
89
  "{u'loc': [4, 4], u'_id': ObjectId('...')}"
94
 
  "{u'loc': [2, 5], u'_id': ObjectId('...')}"
95
90
 
96
91
geoNear queries are also supported using :class:`~bson.son.SON`::
97
92