dmitrymomot/mongodb-querybuilder

A query builder for mongodb

0.1.2 2017-08-03 13:42 UTC

This package is auto-updated.

Last update: 2024-11-12 23:25:23 UTC


README

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