@@ -60,3 +60,117 @@ To query a :doc:`2d </core/2d>` index, use:
60
60
{ geoNear : <collection> , near : [ <coordinates> ] }
61
61
62
62
.. read-lock, slave-ok
63
+
64
+ Example
65
+ -------
66
+
67
+ The following runs the :dbcommand:`geoNear` command on the collection ``places``:
68
+
69
+ .. code-block:: javascript
70
+
71
+ db.runCommand( { geoNear : "places",
72
+ near : { type : "Point",
73
+ coordinates : [ -74.00, 40.00 ] },
74
+ spherical : true } )
75
+
76
+ This operation returns the following output:
77
+
78
+ .. code-block:: javascript
79
+
80
+ {
81
+ "results" : [
82
+ {
83
+ "dis" : 85753.24625705236,
84
+ "obj" : {
85
+ "_id" : ObjectId("536943463d2edb9288571e55"),
86
+ "loc" : {
87
+ "type" : "Point",
88
+ "coordinates" : [
89
+ -73.97,
90
+ 40.77
91
+ ]
92
+ },
93
+ "name" : "Central Park",
94
+ "category" : "Parks"
95
+ }
96
+ },
97
+ {
98
+ "dis" : 87422.73772813451,
99
+ "obj" : {
100
+ "_id" : ObjectId("536943603d2edb9288571e56"),
101
+ "loc" : {
102
+ "type" : "Point",
103
+ "coordinates" : [
104
+ -73.88,
105
+ 40.78
106
+ ]
107
+ },
108
+ "name" : "La Guardia Airport",
109
+ "category" : "Airport"
110
+ }
111
+ }
112
+ ],
113
+ "stats" : {
114
+ "nscanned" : NumberLong(32),
115
+ "objectsLoaded" : NumberLong(32),
116
+ "avgDistance" : 86587.99199259344,
117
+ "maxDistance" : 87422.73772813451,
118
+ "time" : 2
119
+ },
120
+ "ok" : 1
121
+ }
122
+
123
+ Output
124
+ ------
125
+
126
+ The :dbcommand:`geoNear` command returns a document with the
127
+ following fields:
128
+
129
+ .. data:: geoNear.results
130
+
131
+ An array with the results of the :dbcommand:`geoNear` command, sorted
132
+ by distance with the nearest result listed first and farthest last.
133
+
134
+ .. data:: geoNear.results[n].dis
135
+
136
+ For each document in the results, the distance from the coordinates
137
+ defined in the :dbcommand:`geoNear` command.
138
+
139
+ .. data:: geoNear.results[n].obj
140
+
141
+ The document from the collection.
142
+
143
+ .. data:: geoNear.stats
144
+
145
+ An object with statistics about the query used to return the results of
146
+ the :dbcommand:`geoNear` search.
147
+
148
+ .. data:: geoNear.stats.nscanned
149
+
150
+ The total number of index entries scanned during the database operation.
151
+
152
+ .. data:: geoNear.stats.objectsLoaded
153
+
154
+ The total number of documents read from disk during the database operation.
155
+
156
+ .. data:: geoNear.stats.avgDistance
157
+
158
+ The average distance between the coordinates defined in the
159
+ :dbcommand:`geoNear` command and coordinates of the documents returned
160
+ as results.
161
+
162
+ .. data:: geoNear.stats.maxDistance
163
+
164
+ The maximum distance between the coordinates defined in the
165
+ :dbcommand:`geoNear` command and coordinates of the documents returned
166
+ as results.
167
+
168
+ .. data:: geoNear.stats.time
169
+
170
+ The execution time of the database operation, in milliseconds.
171
+
172
+ .. data:: geoNear.ok
173
+
174
+ A value of ``1`` indicates the :dbcommand:`geoNear` search succeeded. A
175
+ value of ``0`` indicates an error.
176
+
0 commit comments