0
Environment:
 python: 3.8
 mongodb: 3.4 (on docker container)
 mongoengine: 0.20.0

One collection in mongodb, DEVICE, with 104 documents populated. There are 9 ReferenceField attributes in the DEVICE collection. The total size of documents from referenced fields are much larger than each DEVICE doc itself.

If I test the performance of the following query,

1. Device.objects(name=name).first()
2. Device.objects(name=name).no_dereference().first()

no matter the test is on the mongodb host or from a remote host, the performance of the first statement is so much better than the second statement.

Wondering why the second statement performance is so much worse than the first statement. What does no_dereference() call actuall do? What's the general guideline on when to use, and when not to use the no_dereference() call?

thanks

2
  • no_dereference is used to turn off any dereferencing for the results of this queryset, the refenrenceField will not fetch to the query. Caused your collection is too small, about 104 documents, so the time for query by two statement will too short for you compare. with large collection, the two statement always better performance. I also try with small collection, the result varied between the two sides because of the server's network connection to the database Commented Dec 13, 2023 at 9:28
  • @TanThien I didn't expect query 2 performs that much better that query 1 with the data set I have. But I didn't expect query 2 always takes 1.5+x time than query 1 either. Commented Dec 18, 2023 at 23:15

0

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.