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
719fd253
Commit
719fd253
authored
Apr 29, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-93: Insert result classes should always track IDs
parent
619c27d8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
14 deletions
+20
-14
Collection.php
src/Collection.php
+9
-4
InsertManyResult.php
src/InsertManyResult.php
+5
-4
InsertOneResult.php
src/InsertOneResult.php
+6
-6
No files found.
src/Collection.php
View file @
719fd253
...
@@ -961,7 +961,7 @@ class Collection
...
@@ -961,7 +961,7 @@ class Collection
*
*
* @see http://docs.mongodb.org/manual/reference/command/insert/
* @see http://docs.mongodb.org/manual/reference/command/insert/
*
*
* @param array $documents The documents to insert
* @param array
[]|object[]
$documents The documents to insert
* @return InsertManyResult
* @return InsertManyResult
*/
*/
public
function
insertMany
(
array
$documents
)
public
function
insertMany
(
array
$documents
)
...
@@ -976,6 +976,8 @@ class Collection
...
@@ -976,6 +976,8 @@ class Collection
if
(
$insertedId
!==
null
)
{
if
(
$insertedId
!==
null
)
{
$insertedIds
[
$i
]
=
$insertedId
;
$insertedIds
[
$i
]
=
$insertedId
;
}
else
{
$insertedIds
[
$i
]
=
is_array
(
$document
)
?
$document
[
'_id'
]
:
$document
->
_id
;
}
}
}
}
...
@@ -989,11 +991,10 @@ class Collection
...
@@ -989,11 +991,10 @@ class Collection
*
*
* @see http://docs.mongodb.org/manual/reference/command/insert/
* @see http://docs.mongodb.org/manual/reference/command/insert/
*
*
* @param array $document The document to insert
* @param array|object $document The document to insert
* @param array $options Additional options
* @return InsertOneResult
* @return InsertOneResult
*/
*/
public
function
insertOne
(
array
$document
)
public
function
insertOne
(
$document
)
{
{
$options
=
array_merge
(
$this
->
getWriteOptions
());
$options
=
array_merge
(
$this
->
getWriteOptions
());
...
@@ -1001,6 +1002,10 @@ class Collection
...
@@ -1001,6 +1002,10 @@ class Collection
$id
=
$bulk
->
insert
(
$document
);
$id
=
$bulk
->
insert
(
$document
);
$wr
=
$this
->
manager
->
executeBulkWrite
(
$this
->
ns
,
$bulk
,
$this
->
wc
);
$wr
=
$this
->
manager
->
executeBulkWrite
(
$this
->
ns
,
$bulk
,
$this
->
wc
);
if
(
$id
===
null
)
{
$id
=
is_array
(
$document
)
?
$document
[
'_id'
]
:
$document
->
_id
;
}
return
new
InsertOneResult
(
$wr
,
$id
);
return
new
InsertOneResult
(
$wr
,
$id
);
}
}
...
...
src/InsertManyResult.php
View file @
719fd253
...
@@ -16,7 +16,7 @@ class InsertManyResult
...
@@ -16,7 +16,7 @@ class InsertManyResult
* Constructor.
* Constructor.
*
*
* @param WriteResult $writeResult
* @param WriteResult $writeResult
* @param
array
$insertedIds
* @param
mixed[]
$insertedIds
*/
*/
public
function
__construct
(
WriteResult
$writeResult
,
array
$insertedIds
=
array
())
public
function
__construct
(
WriteResult
$writeResult
,
array
$insertedIds
=
array
())
{
{
...
@@ -41,10 +41,11 @@ class InsertManyResult
...
@@ -41,10 +41,11 @@ class InsertManyResult
* Return the map of inserted IDs that were generated by the driver.
* Return the map of inserted IDs that were generated by the driver.
*
*
* The index of each ID in the map corresponds to the document's position
* The index of each ID in the map corresponds to the document's position
* in bulk operation. If an inserted document already had an ID (e.g. it was
* in bulk operation. If the document already an ID prior to insertion (i.e.
* generated by the application), it will not be present in this map.
* the driver did not need to generate an ID), this will contain its "_id".
* Any driver-generated ID will be an MongoDB\Driver\ObjectID instance.
*
*
* @return
array
* @return
mixed[]
*/
*/
public
function
getInsertedIds
()
public
function
getInsertedIds
()
{
{
...
...
src/InsertOneResult.php
View file @
719fd253
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
namespace
MongoDB
;
namespace
MongoDB
;
use
BSON\ObjectId
;
use
MongoDB\Driver\WriteResult
;
use
MongoDB\Driver\WriteResult
;
/**
/**
...
@@ -17,9 +16,9 @@ class InsertOneResult
...
@@ -17,9 +16,9 @@ class InsertOneResult
* Constructor.
* Constructor.
*
*
* @param WriteResult $writeResult
* @param WriteResult $writeResult
* @param
ObjectId
$insertedId
* @param
mixed
$insertedId
*/
*/
public
function
__construct
(
WriteResult
$writeResult
,
ObjectId
$insertedId
=
null
)
public
function
__construct
(
WriteResult
$writeResult
,
$insertedId
)
{
{
$this
->
writeResult
=
$writeResult
;
$this
->
writeResult
=
$writeResult
;
$this
->
insertedId
=
$insertedId
;
$this
->
insertedId
=
$insertedId
;
...
@@ -41,10 +40,11 @@ class InsertOneResult
...
@@ -41,10 +40,11 @@ class InsertOneResult
/**
/**
* Return the inserted ID that was generated by the driver.
* Return the inserted ID that was generated by the driver.
*
*
* If the inserted document already had an ID (e.g. it was generated by the
* If the document already an ID prior to insertion (i.e. the driver did not
* application), this will be null.
* need to generate an ID), this will contain its "_id". Any
* driver-generated ID will be an MongoDB\Driver\ObjectID instance.
*
*
* @return
ObjectId|null
* @return
mixed
*/
*/
public
function
getInsertedId
()
public
function
getInsertedId
()
{
{
...
...
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