I am trying to extract some data from a mongodatabase. My collection is structured in this way:
_id:5d306db32e98f83520ae90b7 entity_id:"360803e052b511e3bc11180373d69d01" entity_type_name_item:"TEST" entity_name_item:"Sea" data:"{"json"}" file_type:"list" entity_name:"000001"
I need to extract the json file in "data" and do some operation. The code is working but is really, really slow when I try to loop through the cursor:
for entity in entity_list:
cursor = db[coll_name].find({'entity_id':entity})
for document in cursor:
jdata = json.loads(document['data'])
Do you have any suggestion?
projectionparams. pymongo.readthedocs.io/en/stable/api/pymongo/… . In addition, you can fetch all the entities in one query using the$inopetator (docs.mongodb.com/manual/reference/operator/query/in)db[coll_name].find({'entity_id': {'$in': entity_list}})