Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to reduce time when query doc from mongo with motor driver #360

Open
luckystar1992 opened this issue Aug 30, 2021 · 0 comments
Open

Comments

@luckystar1992
Copy link

Here are my doc defination:


from motor.motor_asyncio import AsyncIOMotorClient
from umongo.frameworks import MotorAsyncIOInstance

motor_instance = MotorAsyncIOInstance()
database = AsyncIOMotorClient(uri)
motor_instance.set_db(database['collection_name'])

@motor_instance.register
class ChildChildDoc(EmbeddedDocument):
    p1 = fields.Str(required=True)
    ....
    pn = fields.Str(required=True)

@motor_instance.register
class ChildDoc(EmbeddedDocument):
    p1 = fields.Str(required=True)
    ....
    p_another_child_list =  fields.ListFields(fields.EmbeddedFields(ChildChildDoc))

@motor_instance.register
Doc1(Document):
    p1 = fields.Str(required=True)
    ....
    p_child_list= fields.ListFields(fields.EmbeddedFields(ChildDoc))

When i have a query calling in my hanlder

#methods1 using the OO query:
result = Doc1().find({"p1" : {"$in": ["l1","l2","l3"]}})
for doc in await result.to_list(length=100):
     other coding

# methods2 using motor async query:

cursor = collection.find({"p1" : {"$in": ["l1","l2","l3"]}})
for doc in await result.to_list(length=100):
     other coding

Both methods return data successuful, but the first method take more time than the second method(700ms v.s. 50ms). I think the deserialization process in each iteration spends time in the first method.

Is there any problem in my code. If not, how can I change my method to reduce the running time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant