mongodb - Pymongo - Fastest way to query all documents -


i have file contain nested dictionary save on computer, when need file, used line of code :

u_i = pickle.load(open("f:\\fortestcode\\user_item_21_07.p", "rb"))

this type data in u_i :

{"bf0e6cf26097ff44b56eba795f25b48a" : {"557252215845" : 1.0},         "9ffa99a1374cd953a30cb1f746f11c6a" : { "978076659142" : 1.0, "622" : 1.0}                } 

and then, inserted nested dictionary mongodb, became :

{     "_id" : objectid("57971bcffefb610990cc5eaa"),     "bf0e6cf26097ff44b56eba795f25b48a" : {         "557252215845" : 1.0     } }  {     "_id" : objectid("57971bcffefb610990cc5ec6"),     "9ffa99a1374cd953a30cb1f746f11c6a" : {         "978076659142" : 1.0,         "622" : 1.0     } } 

so, if need put documents in mongodb 1 file u_i above need make loop :

temp_dict = {} documents_u_i = collection_u_i.find({}) records in documents_u_i:    item in records:        if item != "_id": # dont need key , values of `_id`            temp_dict[item] = records[item] 

and temp_dict nested dictionary u_i above.

temp_dict = {"bf0e6cf26097ff44b56eba795f25b48a" : {"557252215845" : 1.0},         "9ffa99a1374cd953a30cb1f746f11c6a" : { "978076659142" : 1.0, "622" : 1.0}                } 

but don't want used for loop cause in db have > 90.000 documents

is there fastest way query data without using for loop ?

thanks me !


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -