| Steps To Reproduce: |
from bson import SON
|
from pymongo import Connection
|
from pymongo.errors import OperationFailure, AutoReconnect
|
|
db = Connection()["test"]
|
db.users.insert({"loc": [1, 2]})
|
db.users.insert({"loc": [2, 3]})
|
db.users.insert({"loc": [3, 4]})
|
db.users.ensure_index([("loc", "2dsphere")])
|
|
#right way just raise error
|
try:
|
db.command(SON([('geoNear', 'users'), ('near', {'type': 'Point', 'coordinates': [100, 500]}), ('spherical', True),
|
('minDistance', 0), ('query', {"loc": {"$exists": True}}), ('num', 48)]))
|
except OperationFailure as e:
|
print e
|
""">>> command SON([('geoNear', 'users'), ('near', {'type': 'Point', 'coordinates': [100, 500]}), ('spherical', True),
|
('minDistance', 0), ('query', {'push': {'$gt': 0}}), ('num', 48)]) failed: exception: 'near' field must be point"""
|
|
|
|
#wrong way but result is ok
|
print db.command(SON([('geoNear', 'users'), ('near', [120.466, 31.2051]), ('spherical', True), ('minDistance', 0),
|
('query', {"loc": {"$exists": True}}), ('num', 48)]))["ok"]
|
|
""">>> 1.0"""
|
|
|
#wrong way crash the server
|
try:
|
db.command(SON([('geoNear', 'users'), ('near', [1210.466, 31.2051]), ('spherical', True), ('minDistance', 0),
|
('query', {"loc": {"$exists": True}}), ('num', 48)]))
|
except AutoReconnect as e:
|
print e
|
|
""">>>connection closed"""
|
|