0

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?

1

1 Answer 1

1

I believe that losing speed occurs in part where you make the query.

You can speed up this part using:

find({'entity_id': {'$in': entity_list}})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.