Answer the question
In order to leave comments, you need to log in
Why is MongoDB fetching documents very slowly?
Hello.
Such a thing. Mongo executes the query very quickly, but foreach traversal of the data takes a very long time. I measure time with a function microtime()
The result of the output of the function
microtime(true)
// 1464330248.2163
$MongoCollection = (new \MongoClient())->selectCollection('db', 'coll');
$MongoCursor = $MongoCollection->find($where, $fields)->sort($sort)->limit(50)->skip($this->offset);
// 1464330248.2165
foreach($MongoCursor as $doc) {
}
// 1464330253.6667
Answer the question
In order to leave comments, you need to log in
Mongo executes the query very quickly, but foreach traversal of the data takes a very long time.
Well, for starters, look at
https://docs.mongodb.com/manual/reference/method/d...
Secondly - why do you need cursors? They have always been a brake point in all DBMS compared to direct queries.
Their use is justified in case of tricky-complex processing on the server - which is not observed in this case.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question