PHP code example of dmitrymomot / mongodb-querybuilder

1. Go to this page and download the library: Download dmitrymomot/mongodb-querybuilder library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dmitrymomot / mongodb-querybuilder example snippets


/** @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();