This repository has been archived by the owner on Nov 11, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #321 from doctrine/feature/mongodb-docs
Starting docs for doctrine/mongodb.
- Loading branch information
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
Introduction | ||
============ | ||
|
||
The Doctrine MongoDB project is an abstraction layer on top of MongoDB that the Doctrine MongoDB ODM project is built on top of. | ||
|
||
.. note:: | ||
|
||
It wraps the legacy PHP driver and is in bug-fixes-only mode. | ||
|
||
Connecting | ||
---------- | ||
|
||
Creating new connections is easy using the ``Doctrine\MongoDB\Connection`` class: | ||
|
||
.. code-block:: php | ||
use Doctrine\MongoDB\Connection; | ||
$connection = new Connection('mongodb://localhost'); | ||
Databases | ||
--------- | ||
|
||
With the connection you can start selecting databases using the ``selectDatabase`` method: | ||
|
||
.. code-block:: php | ||
$database = $connection->selectDatabase('my_project_database'); | ||
Collections | ||
----------- | ||
|
||
Now you are ready to select a collection and insert some data using the ``insert`` method: | ||
|
||
.. code-block:: php | ||
$users = $database->selectCollection('users'); | ||
$user = [ | ||
'username' => 'jwage', | ||
]; | ||
$users->insert($user); | ||
Reading | ||
------- | ||
|
||
Reading data is easy using the ``find`` and ``findOne`` methods: | ||
|
||
.. code-block:: php | ||
$user = $users->findOne(['username' => 'jwage']); | ||
Updating | ||
-------- | ||
|
||
Updating a record is simple using the ``update`` method: | ||
|
||
.. code-block:: php | ||
$users->update(['username' => 'jwage'], ['$set' => ['isActive' => true]]); | ||
Deleting | ||
------- | ||
|
||
Delete data from the collection using the ``remove`` method: | ||
|
||
.. code-block:: php | ||
$collection->remove(['username' => 'jwage']); | ||