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
3c9064a8
Unverified
Commit
3c9064a8
authored
Aug 01, 2019
by
Andreas Braun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-242: Refactor FindAndModify to use field path syntax in type map
parent
e0908555
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
11 deletions
+38
-11
FindAndModify.php
src/Operation/FindAndModify.php
+4
-11
FunctionsTest.php
tests/FunctionsTest.php
+34
-0
No files found.
src/Operation/FindAndModify.php
View file @
3c9064a8
...
@@ -216,21 +216,14 @@ class FindAndModify implements Executable, Explainable
...
@@ -216,21 +216,14 @@ class FindAndModify implements Executable, Explainable
}
}
$cursor
=
$server
->
executeWriteCommand
(
$this
->
databaseName
,
new
Command
(
$this
->
createCommandDocument
(
$server
)),
$this
->
createOptions
());
$cursor
=
$server
->
executeWriteCommand
(
$this
->
databaseName
,
new
Command
(
$this
->
createCommandDocument
(
$server
)),
$this
->
createOptions
());
$result
=
current
(
$cursor
->
toArray
());
if
(
!
isset
(
$result
->
value
))
{
return
null
;
}
if
(
!
is_object
(
$result
->
value
))
{
throw
new
UnexpectedValueException
(
'findAndModify command did not return a "value" document'
);
}
if
(
isset
(
$this
->
options
[
'typeMap'
]))
{
if
(
isset
(
$this
->
options
[
'typeMap'
]))
{
return
\MongoDB\apply_type_map_to_document
(
$result
->
value
,
$this
->
options
[
'typeMap'
]
);
$cursor
->
setTypeMap
(
\MongoDB\create_field_path_type_map
(
$this
->
options
[
'typeMap'
],
'value'
)
);
}
}
return
$result
->
value
;
$result
=
current
(
$cursor
->
toArray
());
return
isset
(
$result
->
value
)
?
$result
->
value
:
null
;
}
}
public
function
getCommandDocument
(
Server
$server
)
public
function
getCommandDocument
(
Server
$server
)
...
...
tests/FunctionsTest.php
View file @
3c9064a8
...
@@ -58,6 +58,40 @@ class FunctionsTest extends TestCase
...
@@ -58,6 +58,40 @@ class FunctionsTest extends TestCase
'z'
=>
new
BSONArray
([
1
,
2
,
3
]),
'z'
=>
new
BSONArray
([
1
,
2
,
3
]),
]),
]),
],
],
[
[
'x'
=>
1
,
'random'
=>
[
'foo'
=>
'bar'
,
],
'value'
=>
[
'bar'
=>
'baz'
,
'embedded'
=>
[
'foo'
=>
'bar'
,
],
],
],
[
'root'
=>
'array'
,
'document'
=>
'stdClass'
,
'array'
=>
'array'
,
'fieldPaths'
=>
[
'value'
=>
'array'
,
],
],
[
'x'
=>
1
,
'random'
=>
(
object
)
[
'foo'
=>
'bar'
,
],
'value'
=>
[
'bar'
=>
'baz'
,
'embedded'
=>
(
object
)
[
'foo'
=>
'bar'
,
],
],
],
]
];
];
}
}
...
...
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