Hi all.
Is such a thing. Mongo runs a query very quickly but the bypass data to the foreach-eat takes a very long time. Measure the time a function
microtime()
The result of the function output
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
As seen in the example, the cycle lasts as much as three seconds. This is the case even if in the loop nothing happens.
Use MongoDB v3.2.6
The index to be built for queries.
Give your full query filter (condition), sorting, skip and limit - Bianka0 commented on July 9th 19 at 11:22
If you need text search use the full text index. If you want to search some key words, you can make an array (with an index) for that. - Bianka0 commented on July 9th 19 at 11:28