This package is abandoned and no longer maintained. The author suggests using the league/monga package instead.

Mongo Query Builder

1.3 2012-11-28 09:16 UTC

This package is not auto-updated.

Last update: 2019-02-20 17:17:57 UTC


This project is abandoned, if you want to take over it please send me a message on Twitter - @alexbilbie

A PHP MongoDB query builder library

Install via Packagist and Composer

Add the following into your composer.json file:

	"require": {
		"alexbilbie/mongoqb": "*"

Then run

composer install

Install via Git

git clone git://

Download a zip/tarball

Download the latest version:

(Note the zip/tarball won't include any unit tests or composer files)

Unit tests

Master branch Build Status

Develop branch Build Status

The library currently has 100% unit test coverage. To run the unit test suite make sure you have MongoDB installed locally and running with no authentication and on the default port - 27017.

Then run:

composer update --dev
cd vendor/alexbilbie/mongoqb
phpunit -c tests/phpunit.xml

Example usage

Connect to the database

$qb = \MongoQB\Builder(array(
	'dsn'	=>	'mongodb://user:pass@localhost:27017/databaseName'

Insert a document

$qb->insert('collectionName', [
	'name'	=>	'Alex',
	'age'	=>	22,
	'likes'	=>	['whisky', 'gin']

Update a single document

	->where(['name' => 'Alex'])
		'country' => 'UK',
		'job' => 'Developer'
	->push('likes', ['PHP', 'coffee'])

Delete a single document

	->where(['name' => 'Alex'])

Search for matching documents

$results = $qb
	->whereGt('age', 21)
	->whereIn('likes', ['whisky'])
	->where('country', 'UK')

If you find any bugs please file a report in the Issue tracker

If you find this software useful please consider donating, thank you =]