For the same query, using mongoTemplate will be much slower. using mongodb tool, the execution plan will be very fast, and the difference is very big.
- It seems that your two screenshots do not execute a query (at least the second screenshot has sort and the first Java code does not).
- Since this is not a graphical interface and the execution plan is folded up and cannot be seen, it is impossible to judge whether the meaning of 50 in the second screenshot is representative or not, which affects the execution plan to take only the first 50 results. In contrast, the Java code will take out all the results. This will cause great time difference.
Finally, some additional suggestions are irrelevant to the subject. Codes, logs, execution results and the like that can be pasted with text are pasted with text. Not only does the picture look inconvenient, but sometimes it is not complete enough to answer questions. And sometimes we need to use your code, data, etc. to do tests. If there are only screenshots at this time, basically many people will give up on the spot.