发布于 2015-09-14 15:07:03 | 186 次阅读 | 评论: 0 | 来源: 网络整理
The $near operator takes an argument, coordinates for a point in the form of [x, y], and returns a list of objects sorted by distance from nearest to farthest with respect to those coordinates. See the following example:
db.collection.find( { location: { $near: [100,100] } } );
This query will return 100 ordered records with a location field in collection. Specify a different limit using the cursor.limit(), or another geolocation operator, or a non-geospatial operator to limit the results of the query.
注解
Specifying a batch size (i.e. batchSize()) in conjunction with queries that use the $near is not defined. See SERVER-5236 for more information.
在 2.2.3 版更改: Before 2.2.3, a geospatial index must exist on a field holding coordinates before using any of the geolocation query operators. After 2.2.3, applications may use geolocation query operators without having a geospatial index; however, geospatial indexes will support much faster geospatial queries than the unindexed equivalents.
注解
A geospatial index must exist on a field and the field must hold coordinates before you can use any of the geolocation query operators.