Skip to content

Commit bdda485

Browse files
committed
Merge branch 'v1.0'
2 parents 69da800 + f66f430 commit bdda485

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed

docs/upgrade-guide.md

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ between [updating specific fields][update] and
8383
[MongoDB\Collection][collection] does not yet have a helper method for the
8484
[group][group] command; however, that is planned in [PHPLIB-177][jira-group].
8585
The following example demonstrates how to execute a group command using
86-
[Database::command()](classes/database.md#command):
86+
[Database::command()][command]:
87+
88+
[command]: classes/database.md#command
8789

8890
```php
8991
<?php
@@ -108,7 +110,7 @@ $resultDocument = $cursor->toArray()[0];
108110
[MongoDB\Collection][collection] does not yet have a helper method for the
109111
[mapReduce][mapReduce] command; however, that is planned in
110112
[PHPLIB-53][jira-mapreduce]. The following example demonstrates how to execute a
111-
mapReduce command using [Database::command()](classes/database.md#command):
113+
mapReduce command using [Database::command()][command]:
112114

113115
```php
114116
<?php
@@ -139,8 +141,11 @@ with [DBRef][dbref] objects; however, that is planned in
139141

140142
[MongoCollection::save()][save], which was syntactic sugar for an insert or
141143
upsert operation, has been removed in favor of explicitly using
142-
[insertOne()](classes/collection.md#insertone) or
143-
[replaceOne()](classes/collection.md#replaceone) (with the "upsert" option).
144+
[insertOne()][insertone] or [replaceOne()][replaceone] (with the "upsert"
145+
option).
146+
147+
[insertone]: classes/collection.md#insertone
148+
[replaceone]: classes/collection.md#replaceone
144149

145150
![save() flowchart](img/save-flowchart.png)
146151

@@ -152,11 +157,37 @@ insert or replace the document and handle the returned InsertResult or
152157
UpdateResult, respectively. This also helps avoid inadvertent and potentially
153158
dangerous [full-document replacements][replace].
154159

160+
### Accessing IDs of Inserted Documents
161+
162+
In the legacy driver, [MongoCollection::insert()][insert],
163+
[MongoCollection::batchInsert()][batchinsert], and
164+
[MongoCollection::save()][save] (when inserting) would modify their input
165+
argument by injecting an "_id" key containing the generated ObjectId (i.e.
166+
[MongoId][mongoid] object). This behavior was a bit of a hack, as it did not
167+
rely on the argument being [passed by reference][byref]; it directly modified
168+
memory through the extension API and could not be implemented in PHP userland.
169+
As such, it is no longer done in the new driver and library.
170+
171+
[insert]: http://php.net/manual/en/mongocollection.insert.php
172+
[batchinsert]: http://php.net/manual/en/mongocollection.batchinsert.php
173+
[mongoid]: http://php.net/manual/en/class.mongoid.php
174+
[byref]: http://php.net/manual/en/language.references.pass.php
175+
176+
IDs of inserted documents (whether generated or not) may be accessed through the
177+
result objects returned by the write methods:
178+
179+
* MongoDB\InsertOneResult::getInsertedId() for [insertOne()][insertone]
180+
* MongoDB\InsertManyResult::getInsertedIds() for [insertMany()][insertmany]
181+
* MongoDB\BulkWriteResult::getInsertedIds() for [bulkWrite()][bulkwrite]
182+
183+
[insertmany]: classes/collection.md#insertmany
184+
[bulkwrite]: classes/collection.md#bulkwrite
185+
155186
### MongoWriteBatch
156187

157188
The legacy driver's [MongoWriteBatch][batch] classes have been replaced with a
158-
general-purpose [bulkWrite()](classes/collection.md#bulkwrite) method. Whereas
159-
the legacy driver only allowed bulk operations of the same time, the new method
160-
allows operations to be mixed (e.g. inserts, updates, and deletes).
189+
general-purpose [bulkWrite()][bulkwrite] method. Whereas the legacy driver only
190+
allowed bulk operations of the same time, the new method allows operations to be
191+
mixed (e.g. inserts, updates, and deletes).
161192

162193
[batch]: http://php.net/manual/en/class.mongowritebatch.php

0 commit comments

Comments
 (0)