A query builder for mongodb
require this library through composer:
composer require algatux/mongodb-querybuilder:dev-master
##Usage example
/** @var \MongoDB\Collection $mongodbCollection */
$builder = new QueryBuilder($mongodbCollection);
/** @var \MongoDB\Driver\Cursor $cursor */
$cursor = $builder
->select('_id', 'field1') // projection
->and(
$builder->expr()->or( // $or
['field1' => 'value1'],
['field2' => 'value2'],
),
['field3' => 'value3']
) // $and
->sort(['field1' => -1]) // sort option
->limit(10) // limit option
->skip(2) // skip option
->setQueryOption('foo', $bar) // adds not actually method supported options
->find() // will trigger $collection->find() method
->getQuery()
->execute();