Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongo-php-library
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
mongo-php-library
Commits
f66f430a
Commit
f66f430a
authored
Mar 30, 2016
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Discuss how inserted IDs may be accessed in Upgrade Guide
parent
2c98016f
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
1 deletion
+26
-1
upgrade-guide.md
docs/upgrade-guide.md
+26
-1
No files found.
docs/upgrade-guide.md
View file @
f66f430a
...
@@ -157,6 +157,32 @@ insert or replace the document and handle the returned InsertResult or
...
@@ -157,6 +157,32 @@ insert or replace the document and handle the returned InsertResult or
UpdateResult, respectively. This also helps avoid inadvertent and potentially
UpdateResult, respectively. This also helps avoid inadvertent and potentially
dangerous
[
full-document replacements
][
replace
]
.
dangerous
[
full-document replacements
][
replace
]
.
### Accessing IDs of Inserted Documents
In the legacy driver,
[
MongoCollection::insert()
][
insert
]
,
[
MongoCollection::batchInsert()
][
batchinsert
]
, and
[
MongoCollection::save()
][
save
]
(when inserting) would modify their input
argument by injecting an "_id" key containing the generated ObjectId (i.e.
[
MongoId
][
mongoid
]
object). This behavior was a bit of a hack, as it did not
rely on the argument being
[
passed by reference
][
byref
]
; it directly modified
memory through the extension API and could not be implemented in PHP userland.
As such, it is no longer done in the new driver and library.
[
insert
]:
http://php.net/manual/en/mongocollection.insert.php
[
batchinsert
]:
http://php.net/manual/en/mongocollection.batchinsert.php
[
mongoid
]:
http://php.net/manual/en/class.mongoid.php
[
byref
]:
http://php.net/manual/en/language.references.pass.php
IDs of inserted documents (whether generated or not) may be accessed through the
result objects returned by the write methods:
*
MongoDB
\I
nsertOneResult::getInsertedId() for
[
insertOne()
][
insertone
]
*
MongoDB
\I
nsertManyResult::getInsertedIds() for
[
insertMany()
][
insertmany
]
*
MongoDB
\B
ulkWriteResult::getInsertedIds() for
[
bulkWrite()
][
bulkwrite
]
[
insertmany
]:
classes/collection.md#insertmany
[
bulkwrite
]:
classes/collection.md#bulkwrite
### MongoWriteBatch
### MongoWriteBatch
The legacy driver's
[
MongoWriteBatch
][
batch
]
classes have been replaced with a
The legacy driver's
[
MongoWriteBatch
][
batch
]
classes have been replaced with a
...
@@ -165,4 +191,3 @@ allowed bulk operations of the same time, the new method allows operations to be
...
@@ -165,4 +191,3 @@ allowed bulk operations of the same time, the new method allows operations to be
mixed (e.g. inserts, updates, and deletes).
mixed (e.g. inserts, updates, and deletes).
[
batch
]:
http://php.net/manual/en/class.mongowritebatch.php
[
batch
]:
http://php.net/manual/en/class.mongowritebatch.php
[
bulkwrite
]:
classes/collection.md#bulkwrite
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment