March 2019
Intermediate to advanced
394 pages
11h 4m
English
Creating documents is a two-step process. First, we create our document and set the attribute values:
$book = new Book();$book->setName('MongoDB with Doctrine');$book->setPrice(45);
Following this, we ask Doctrine to save $book in the next flush() call:
$dm->persist($book);
We can force saving by manually calling flush(), as follows:
$dm->flush();
In this example, $dm is a DocumentManager object that we use to connect to our MongoDB instance, as follows:
$dm = DocumentManager::create(new Connection(), $config);
Updating a document is as easy as assigning values to the attributes:
$book->price = 39;$book->persist($book);
This will save our MongoDB with Doctrine book with the new price of 39.
Updating documents ...
Read now
Unlock full access