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
d4b5e8d9
Unverified
Commit
d4b5e8d9
authored
Oct 01, 2019
by
Andreas Braun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-481: Add the ability to specify a pipeline to an update within bulk write
parent
9a56bda8
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
174 additions
and
8 deletions
+174
-8
BulkWrite.php
src/Operation/BulkWrite.php
+3
-2
BulkWriteFunctionalTest.php
tests/Operation/BulkWriteFunctionalTest.php
+2
-2
BulkWriteTest.php
tests/Operation/BulkWriteTest.php
+4
-4
updateWithPipelines.json
tests/SpecTests/crud/updateWithPipelines.json
+165
-0
No files found.
src/Operation/BulkWrite.php
View file @
d4b5e8d9
...
...
@@ -33,6 +33,7 @@ use function is_bool;
use
function
is_object
;
use
function
key
;
use
function
MongoDB
\is_first_key_operator
;
use
function
MongoDB
\is_pipeline
;
use
function
MongoDB
\server_supports_feature
;
use
function
sprintf
;
...
...
@@ -255,8 +256,8 @@ class BulkWrite implements Executable
throw
InvalidArgumentException
::
invalidType
(
sprintf
(
'$operations[%d]["%s"][1]'
,
$i
,
$type
),
$args
[
1
],
'array or object'
);
}
if
(
!
is_first_key_operator
(
$args
[
1
]))
{
throw
new
InvalidArgumentException
(
sprintf
(
'First key in $operations[%d]["%s"][1] is n
ot an update operator
'
,
$i
,
$type
));
if
(
!
is_first_key_operator
(
$args
[
1
])
&&
!
is_pipeline
(
$args
[
1
])
)
{
throw
new
InvalidArgumentException
(
sprintf
(
'First key in $operations[%d]["%s"][1] is n
either an update operator nor a pipeline
'
,
$i
,
$type
));
}
if
(
!
isset
(
$args
[
2
]))
{
...
...
tests/Operation/BulkWriteFunctionalTest.php
View file @
d4b5e8d9
...
...
@@ -263,7 +263,7 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
public
function
testUpdateOneRequiresUpdateOperators
()
{
$this
->
expectException
(
InvalidArgumentException
::
class
);
$this
->
expectExceptionMessage
(
'First key in $operations[0]["updateOne"][1] is n
ot an update operator
'
);
$this
->
expectExceptionMessage
(
'First key in $operations[0]["updateOne"][1] is n
either an update operator nor a pipeline
'
);
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
'updateOne'
=>
[[
'_id'
=>
1
],
[
'x'
=>
1
]]],
]);
...
...
@@ -272,7 +272,7 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
public
function
testUpdateManyRequiresUpdateOperators
()
{
$this
->
expectException
(
InvalidArgumentException
::
class
);
$this
->
expectExceptionMessage
(
'First key in $operations[0]["updateMany"][1] is n
ot an update operator
'
);
$this
->
expectExceptionMessage
(
'First key in $operations[0]["updateMany"][1] is n
either an update operator nor a pipeline
'
);
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
'updateMany'
=>
[[
'_id'
=>
[
'$gt'
=>
1
]],
[
'x'
=>
1
]]],
]);
...
...
tests/Operation/BulkWriteTest.php
View file @
d4b5e8d9
...
...
@@ -258,10 +258,10 @@ class BulkWriteTest extends TestCase
]);
}
public
function
testUpdateManyUpdateArgumentRequiresOperators
()
public
function
testUpdateManyUpdateArgumentRequiresOperators
OrPipeline
()
{
$this
->
expectException
(
InvalidArgumentException
::
class
);
$this
->
expectExceptionMessage
(
'First key in $operations[0]["updateMany"][1] is n
ot an update operator
'
);
$this
->
expectExceptionMessage
(
'First key in $operations[0]["updateMany"][1] is n
either an update operator nor a pipeline
'
);
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
BulkWrite
::
UPDATE_MANY
=>
[[
'_id'
=>
[
'$gt'
=>
1
]],
[
'x'
=>
1
]]],
]);
...
...
@@ -345,10 +345,10 @@ class BulkWriteTest extends TestCase
]);
}
public
function
testUpdateOneUpdateArgumentRequiresOperators
()
public
function
testUpdateOneUpdateArgumentRequiresOperators
OrPipeline
()
{
$this
->
expectException
(
InvalidArgumentException
::
class
);
$this
->
expectExceptionMessage
(
'First key in $operations[0]["updateOne"][1] is n
ot an update operator
'
);
$this
->
expectExceptionMessage
(
'First key in $operations[0]["updateOne"][1] is n
either an update operator nor a pipeline
'
);
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
BulkWrite
::
UPDATE_ONE
=>
[[
'_id'
=>
1
],
[
'x'
=>
1
]]],
]);
...
...
tests/SpecTests/crud/updateWithPipelines.json
View file @
d4b5e8d9
...
...
@@ -238,6 +238,171 @@
]
}
}
},
{
"description"
:
"UpdateOne in bulk write using pipelines"
,
"operations"
:
[
{
"name"
:
"bulkWrite"
,
"arguments"
:
{
"requests"
:
[
{
"name"
:
"updateOne"
,
"arguments"
:
{
"filter"
:
{
"_id"
:
1
},
"update"
:
[
{
"$replaceRoot"
:
{
"newRoot"
:
"$t"
}
},
{
"$addFields"
:
{
"foo"
:
1
}
}
]
}
}
]
},
"result"
:
{
"matchedCount"
:
1
,
"modifiedCount"
:
1
,
"upsertedCount"
:
0
}
}
],
"expectations"
:
[
{
"command_started_event"
:
{
"command"
:
{
"update"
:
"test"
,
"updates"
:
[
{
"q"
:
{
"_id"
:
1
},
"u"
:
[
{
"$replaceRoot"
:
{
"newRoot"
:
"$t"
}
},
{
"$addFields"
:
{
"foo"
:
1
}
}
]
}
]
},
"command_name"
:
"update"
,
"database_name"
:
"crud-tests"
}
}
],
"outcome"
:
{
"collection"
:
{
"data"
:
[
{
"_id"
:
1
,
"u"
:
{
"v"
:
1
},
"foo"
:
1
},
{
"_id"
:
2
,
"x"
:
2
,
"y"
:
1
}
]
}
}
},
{
"description"
:
"UpdateMany in bulk write using pipelines"
,
"operations"
:
[
{
"name"
:
"bulkWrite"
,
"arguments"
:
{
"requests"
:
[
{
"name"
:
"updateMany"
,
"arguments"
:
{
"filter"
:
{},
"update"
:
[
{
"$project"
:
{
"x"
:
1
}
},
{
"$addFields"
:
{
"foo"
:
1
}
}
]
}
}
]
},
"result"
:
{
"matchedCount"
:
2
,
"modifiedCount"
:
2
,
"upsertedCount"
:
0
}
}
],
"expectations"
:
[
{
"command_started_event"
:
{
"command"
:
{
"update"
:
"test"
,
"updates"
:
[
{
"q"
:
{},
"u"
:
[
{
"$project"
:
{
"x"
:
1
}
},
{
"$addFields"
:
{
"foo"
:
1
}
}
],
"multi"
:
true
}
]
},
"command_name"
:
"update"
,
"database_name"
:
"crud-tests"
}
}
],
"outcome"
:
{
"collection"
:
{
"data"
:
[
{
"_id"
:
1
,
"x"
:
1
,
"foo"
:
1
},
{
"_id"
:
2
,
"x"
:
2
,
"foo"
:
1
}
]
}
}
}
]
}
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