I am using pymongo to query for all items in a region (actually it is to query for all venues in a region on a map). I used db.command(SON())
before to search in a spherical region, which can return me a dictionary and in the dictionary there is a key called results
which contains the venues. Now I need to search in a square area and I am suggested to use db.places.find
, however, this returns me a pymongo.cursor.Cursor
class and I have no idea how to extract the venue results from it.
Does anyone know whether I should convert the cursor into a dict and extract the results out, or use another method to query for items in a square region?
BTW, db is pymongo.database.Database class
The codes are:
>>> import pymongo
>>> db = pymongo.MongoClient(host).PSRC
>>> resp = db.places.find({"loc": {"$within": {"$box": [[ll_lng,ll_lat], [ur_lng,ur_lat]]}}})
>>> for doc in resp:
>>> print(doc)
I have values of ll_lng, ll_lat, ur_lng and ur_lat, use these values but it prints nothing from this codes
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…