How many separate queries when using populate() #12589
Answered
by
vkarpov15
vresetnikov
asked this question in
Q&A
-
Hello, When using the mongoose's populate() function, how many separate queries are fired? I am asking this because having MongoDB on a separate instance I would like to cut the amount of roundtrips needed for the data to reduce the latency. |
Beta Was this translation helpful? Give feedback.
Answered by
vkarpov15
Nov 1, 2022
Replies: 1 comment
-
1 per populated field by default. Unless you use cursors or |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
vresetnikov
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1 per populated field by default. Unless you use cursors or
perDocumentLimit
. So, for example,await User.find().populate('friends').populate('blogPosts')
, that executes 3 queries: 1 for users, 1 for friends, 1 for blog posts.