Maintained

Unmaintained

Doctrine is a project that aims to handle the persistence of your
domain model in a non-interfering way. Non-relational or no-sql
databases like MongoDB give you flexibility of building data store
around your object model and not vise versa. You can read more on the
initial configuration and setup in Introduction to MongoDB Object
Document Mapper. This section will give you a basic
overview of what could be accomplished using Doctrine MongoDB ODM.

That’s it, we have our models, and we can save and retrieve them. Now
all we need to do is to properly instantiate the DocumentManager
instance. Read more about setting up the Doctrine MongoDB ODM in the
Introduction to MongoDB Object Document Mapper:

Note that you do not need to explicitly call persist on the $post because the operation
will cascade on to the reference automatically.

Now if you did everything correctly, you should have those two objects
stored in MongoDB in correct collections and databases. You can use the
php-mongodb-admin project, hosted on github to look at your
BlogPost collection, where you will see only one document:

If you want to iterate over the posts the user references it is as easy as the following:

<?php
$posts = $dm->getPosts();
foreach ($posts as $post) {
}

You will notice that working with objects is nothing magical and you only have access to the properties,
getters and setters that you have defined yourself so the semantics are very clear. You can continue
reading about the MongoDB in the Introduction to MongoDB Object Document Mapper.