steevej
(Steeve Juneau)
10
I want to add the following.
That kind of look is worthless when testing for performance.
for(var i = 0; i < 100000; i++){
conn.collection('galery').find({ "user_id": req.session.userId}).toArray();
};
That is not realistic of any use case. You are querying the same document over and over. So if the document has to be read from disk it is read only once. Then it sits in cache and it is very fast to retrieve. You should be query for many different user_id, not just one.
I concur with @santimir, 2 completely different queries on 2 different collections for which we have no sample documents, no stats about the number of documents in each, no information about any indexes, no any idea about the number of documents that matches the queries. You mentioned PHP but you do not share the code. Yes a simple find is supposed to be faster than an aggregate, but not if your find returns 10 thousand documents and your aggregate only a few.
That is why you really have to do what @Prasad_Saya mentioned about Explain Results.
Trying to help you is like shooting in the dark on a moving target.
1 Like