I have a document called login. the document contains the following:
-
username
-
password
-
gender
I have another document called history which contains the following:
-
username
-
time
I the history document the username is referenced to login document.
Using the time field I’ll get the details from the history document with the following query.
usersByHistory=models.history.objects(time=searchObj.time)
using the above result I’ll get the user’s information using the following code:
list=[]
for user in usersByHistory :
name = user.user_name.user_name
usersList = login_info.objects(user_name=name)
list.append(usersList)
By executing the above code the execution time is very high, I want to avoid this for loop in the code and replace it with mongoengine query so as to minimize the execution time. someone please help
You could do an
inquery and provide the array of users: http://docs.mongoengine.org/en/latest/guide/querying.html#query-operatorsHeres an example using
scalarbecause we only need a list of user_names.*I have updated the class names and variable names to conform to pep8