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
ba4d4725
Commit
ba4d4725
authored
Sep 14, 2017
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-275: BulkWrite::insert() always returns the ID in 1.3.0+
parent
dcb9d120
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
2 additions
and
40 deletions
+2
-40
BulkWrite.php
src/Operation/BulkWrite.php
+1
-8
InsertMany.php
src/Operation/InsertMany.php
+1
-7
InsertOne.php
src/Operation/InsertOne.php
+0
-4
functions.php
src/functions.php
+0
-21
No files found.
src/Operation/BulkWrite.php
View file @
ba4d4725
...
@@ -311,14 +311,7 @@ class BulkWrite implements Executable
...
@@ -311,14 +311,7 @@ class BulkWrite implements Executable
break
;
break
;
case
self
::
INSERT_ONE
:
case
self
::
INSERT_ONE
:
$insertedId
=
$bulk
->
insert
(
$args
[
0
]);
$insertedIds
[
$i
]
=
$bulk
->
insert
(
$args
[
0
]);
if
(
$insertedId
!==
null
)
{
$insertedIds
[
$i
]
=
$insertedId
;
}
else
{
$insertedIds
[
$i
]
=
\MongoDB\extract_id_from_inserted_document
(
$args
[
0
]);
}
break
;
break
;
case
self
::
REPLACE_ONE
:
case
self
::
REPLACE_ONE
:
...
...
src/Operation/InsertMany.php
View file @
ba4d4725
...
@@ -127,13 +127,7 @@ class InsertMany implements Executable
...
@@ -127,13 +127,7 @@ class InsertMany implements Executable
$insertedIds
=
[];
$insertedIds
=
[];
foreach
(
$this
->
documents
as
$i
=>
$document
)
{
foreach
(
$this
->
documents
as
$i
=>
$document
)
{
$insertedId
=
$bulk
->
insert
(
$document
);
$insertedIds
[
$i
]
=
$bulk
->
insert
(
$document
);
if
(
$insertedId
!==
null
)
{
$insertedIds
[
$i
]
=
$insertedId
;
}
else
{
$insertedIds
[
$i
]
=
\MongoDB\extract_id_from_inserted_document
(
$document
);
}
}
}
$writeConcern
=
isset
(
$this
->
options
[
'writeConcern'
])
?
$this
->
options
[
'writeConcern'
]
:
null
;
$writeConcern
=
isset
(
$this
->
options
[
'writeConcern'
])
?
$this
->
options
[
'writeConcern'
]
:
null
;
...
...
src/Operation/InsertOne.php
View file @
ba4d4725
...
@@ -102,10 +102,6 @@ class InsertOne implements Executable
...
@@ -102,10 +102,6 @@ class InsertOne implements Executable
$bulk
=
new
Bulk
(
$options
);
$bulk
=
new
Bulk
(
$options
);
$insertedId
=
$bulk
->
insert
(
$this
->
document
);
$insertedId
=
$bulk
->
insert
(
$this
->
document
);
if
(
$insertedId
===
null
)
{
$insertedId
=
\MongoDB\extract_id_from_inserted_document
(
$this
->
document
);
}
$writeConcern
=
isset
(
$this
->
options
[
'writeConcern'
])
?
$this
->
options
[
'writeConcern'
]
:
null
;
$writeConcern
=
isset
(
$this
->
options
[
'writeConcern'
])
?
$this
->
options
[
'writeConcern'
]
:
null
;
$writeResult
=
$server
->
executeBulkWrite
(
$this
->
databaseName
.
'.'
.
$this
->
collectionName
,
$bulk
,
$writeConcern
);
$writeResult
=
$server
->
executeBulkWrite
(
$this
->
databaseName
.
'.'
.
$this
->
collectionName
,
$bulk
,
$writeConcern
);
...
...
src/functions.php
View file @
ba4d4725
...
@@ -46,27 +46,6 @@ function apply_type_map_to_document($document, array $typeMap)
...
@@ -46,27 +46,6 @@ function apply_type_map_to_document($document, array $typeMap)
return
\MongoDB\BSON\toPHP
(
\MongoDB\BSON\fromPHP
(
$document
),
$typeMap
);
return
\MongoDB\BSON\toPHP
(
\MongoDB\BSON\fromPHP
(
$document
),
$typeMap
);
}
}
/**
* Extracts an ID from an inserted document.
*
* This function is used when BulkWrite::insert() does not return a generated
* ID, which means that the ID should be fetched from an array offset, public
* property, or in the data returned by bsonSerialize().
*
* @internal
* @see https://jira.mongodb.org/browse/PHPC-382
* @param array|object $document Inserted document
* @return mixed
*/
function
extract_id_from_inserted_document
(
$document
)
{
if
(
$document
instanceof
Serializable
)
{
return
extract_id_from_inserted_document
(
$document
->
bsonSerialize
());
}
return
is_array
(
$document
)
?
$document
[
'_id'
]
:
$document
->
_id
;
}
/**
/**
* Generate an index name from a key specification.
* Generate an index name from a key specification.
*
*
...
...
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