mongodb lte and gte query execution taking too much time

369 views Asked by At

this is my query for find number of record in one hour

         $rec=0;
         $acst1 = new \MongoDB\BSON\UTCDateTime(strtotime('2017-10-30 21:00:00')*1000);
         $acst2 = new \MongoDB\BSON\UTCDateTime(strtotime('2017-10-30 22:00:00')*1000);

         $collection1 = $db->CR800;
         $filter1 = array(TIMESTAMP=> array('$gte' => $acst1, '$lte' => $acst2));
         $rec= $collection1->count($filter1);

when i execute this query it take 16 sec to execute and when remove greater than less than condition then query executes in just 300ms

there are more than 20 million document in collection

is there a way to optimize this query and reduce execution time ?

0

There are 0 answers