MongoEngine/mongoengine

some questions that users are confused about

841020 opened this issue · 1 comments

Hi there

this is not issue
Just some questions that users are confused about

so my question list is here
1.Whether the query to the database has been completed after the QuerySet object is initialized?
2. i knew method like first/ get/ __getitem__/ __iter__/ __next__ basically is iterate QuerySet object (same as iterate self._cursor)
so what is self._cursor mean? i knew self._cursor implement object cache in BaseQuerySet class ,
is self._cursor already executed query from database? or when i iterate it , it will keey query database every time?

I hope the answer can tell me clearly, at what stage are mongoengine executing the query in mongodb

class MyDoc(Document):
   ...

my_docs = MyDoc.objects()    # query not executed yet (pay attention that printing my_docs at this stage will cause the query to be fired)
for doc in my_docs:                 # query is fired here when it starts iterating in the queryset
    ...

I hope this helps