python - mongodb: unreasonable slow query, with index and simple documents -


i using python , mongodb, need query documents database , save information documents, code :

for trips in trip.find({},{'latlng_start':1, 'latlng_end':1, 'trip_data':1, 'trip_id':1}).batch_size(500):     orig_coord = trips['latlng_start']['coordinates']     dest_coord = trips['latlng_end']['coordinates']     cell_start = citymap.find({"trips_orig": {"$exists": true},"cell_latlng":{"$geointersects":{"$geometry":{"type":"point", "coordinates":orig_coord}}}})     cell_end = citymap.find({"trips_dest": {"$exists": true},"cell_latlng":{"$geointersects":{"$geometry":{"type":"point", "coordinates":dest_coord}}}})      if cell_start.count() == 1 , cell_end.count() == 1 , cell_start[0]['big_cell8']['poi'] != {} , cell_end[0]['big_cell8']['poi'] != {}:         try:             labels_raw.append(purpose_mapping[trips['trip_data']['purpose']])                        user_ids_raw.append(int(trips['trip_id'][:10]))                      venue_feature_start.append([cell_start[0]['big_cell8']['poi'], orig_coord])             venue_feature_end.append([cell_end[0]['big_cell8']['poi'], dest_coord])          except:             continue      else:         continue 

i have assigned 2dsphere index collection citymap , indexes of collection are:

[     {         "v" : 1,         "key" : {             "_id" : 1         },         "name" : "_id_",         "ns" : "cityseg2014.grid750"     },     {         "v" : 1,         "key" : {             "latlng" : "2dsphere"         },         "name" : "latlng_2dsphere",         "ns" : "cityseg2014.grid750",         "2dsphereindexversion" : 2     },     {         "v" : 1,         "key" : {             "cell_latlng" : "2dsphere"         },         "name" : "cell_latlng_2dsphere",         "ns" : "cityseg2014.grid750",         "2dsphereindexversion" : 2     },     {         "v" : 1,         "key" : {             "_fts" : "text",             "_ftsx" : 1         },         "name" : "trips_dest_text_trips_orig_text",         "ns" : "cityseg2014.grid750",         "weights" : {             "trips_dest" : 1,             "trips_orig" : 1         },         "default_language" : "english",         "language_override" : "language",         "textindexversion" : 2     } ] 

the problem that, although there 47000 trips , citymap contains 11600 documents, query takes 3000 seconds!!! morning when run same program takes 800 seconds. have no idea why happen. idea improve efficiency?


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

android - MPAndroidChart - How to add Annotations or images to the chart -