Skip to content

Algatux/mongodb-querybuilder

Repository files navigation

mongodb-querybuilder

A query builder for mongodb

PHP Version MongoDB Version Build Status Scrutinizer Code Quality Code Coverage

Latest Stable Version Total Downloads Latest Unstable Version License

Installation

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();

About

A query builder for mongodb

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages