0

I'm trying to run a query in mongodb via php but I don't know how do a 'like' query. I'm getting only specific results.

This is my code:

public function findByField($collection, $field, $value) {
    $returnData = array();
    $filter = [
        $field => $value            
    ];
    $query = new MongoDB\Driver\Query($filter);

    $readPreference = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_PRIMARY);
    $cursor = $this->manager->executeQuery($collection, $query, $readPreference);

    foreach ($cursor as $document) {            
        array_push($returnData, $document);
    }
    return $returnData;
}

This is the driver I am using: http://php.net/manual/en/set.mongodb.php

Thanks in advance for your time.

dmance
  • 628
  • 1
  • 8
  • 26
  • [Didn't it help?](http://stackoverflow.com/questions/3305561/how-to-query-mongodb-with-like?rq=1) – behkod Apr 01 '17 at 15:01
  • Like most of the times, until I don't ask i dont find the answer. I was searching and trying for more than 4 hours before ask. Thanks. – dmance Apr 01 '17 at 19:31

0 Answers0