Search code examples
phpmongodbcursordriver

cursor performace with mongodb php driver


Is there any performance issues with php mongo query cursor handling?

My code:

 $cursor = $collection->find($searchCriteria)->limit($limit_rows);
// Sort ascending based on S_DTTM
$cursor->sort(array('S_DTTM' => 1 , 'SYMBOL' => 1 ));

// How many results found?
$num_docs = $cursor->count(); 

if( $num_docs > 0 )
{
    // loop over the results
    foreach ($cursor as $ticks)
    {

See codes like

// request data 
$result = $cursor->getNext();

My issue is after the first query returns ( full with limit of 100 rows ) the next query just goes on looping. Have millions of rows returning, so I wanted to put the limits with "limit".

I did do re-index just in case, still no difference.

What am I doing wrong? Does the getNext works better?

Using mongod ver 2.5.4 and the latest php mongo driver downloaded a week ago.
Collection size is 100Gb including 2 additional indexes.

mongo log shows all the query executing in less than 200ms.

  • Turns out to be Query Issue and not php mongo driver issue ..

Solution

  • Use of count() and sort() may decrease performance.