Introduction

The Doctrine MongoDB project is an abstraction layer on top of the legacy PHP driver that the Doctrine MongoDB ODM project is built on top of.

This project has been deprecated and the MongoDB ODM project will soon no longer depend on it. The project is also in bug-fixes-only mode.

Connecting

Creating new connections is easy using the Doctrine\MongoDB\Connection class:

1use Doctrine\MongoDB\Connection; $connection = new Connection('mongodb://localhost');
2
3

Databases

With the connection you can start selecting databases using the selectDatabase method:

1$database = $connection->selectDatabase('my_project_database');

Collections

Now you are ready to select a collection and insert some data using the insert method:

1$users = $database->selectCollection('users'); $user = [ 'username' => 'jwage', ]; $users->insert($user);
2
3
4
5
6
7

Reading

Reading data is easy using the find and findOne methods:

1$user = $users->findOne(['username' => 'jwage']);

Updating

Updating a record is simple using the update method:

1$users->update(['username' => 'jwage'], ['$set' => ['isActive' => true]]);

Deleting

Delete data from the collection using the remove method:

1$collection->remove(['username' => 'jwage']);