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
da84ba51
Commit
da84ba51
authored
Dec 05, 2014
by
Hannes Magnusson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHP-1309: Collection::replaceOne()
parent
13ded9a3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
1 deletion
+19
-1
write.php
examples/write.php
+9
-0
Collection.php
src/Collection.php
+10
-1
No files found.
examples/write.php
View file @
da84ba51
...
...
@@ -81,6 +81,15 @@ try {
foreach
(
$result
as
$document
)
{
var_dump
(
$document
);
}
$result
=
$collection
->
replaceOne
(
array
(
"nick"
=>
"Bobby Fischer"
),
array
(
"name"
=>
"Magnus Carlsen"
,
"nick"
=>
"unknown"
,
"citizen"
=>
"Norway"
)
);
printf
(
"Replaced: %d (out of expected 1), verify Bobby has been replaced with Magnus
\n
"
,
$result
->
getNumModified
());
$result
=
$collection
->
find
();
foreach
(
$result
as
$document
)
{
var_dump
(
$document
);
}
$result
=
$collection
->
deleteMany
(
array
(
"citizen"
=>
"Iceland"
));
printf
(
"Deleted: %d (out of expected 3)
\n
"
,
$result
->
getNumRemoved
());
...
...
src/Collection.php
View file @
da84ba51
...
...
@@ -209,9 +209,18 @@ class Collection {
function
deleteMany
(
array
$filter
)
{
/* {{{ */
return
$this
->
_writeSingle
(
$filter
,
self
::
DELETE
,
array
(
"limit"
=>
0
));
}
/* }}} */
function
updateOne
(
array
$filter
,
$update
,
array
$options
=
array
())
{
/* {{{ */
function
updateOne
(
array
$filter
,
array
$update
,
array
$options
=
array
())
{
/* {{{ */
if
(
key
(
$update
)[
0
]
!=
'$'
)
{
throw
new
\RuntimeException
(
"First key in
\$
update must be a
\$
operator"
);
}
return
$this
->
_writeSingle
(
$filter
,
self
::
UPDATE
,
$options
,
$update
);
}
/* }}} */
function
replaceOne
(
array
$filter
,
array
$update
,
array
$options
=
array
())
{
/* {{{ */
if
(
key
(
$update
)[
0
]
==
'$'
)
{
throw
new
\RuntimeException
(
"First key in
\$
update must NOT be a
\$
operator"
);
}
return
$this
->
_writeSingle
(
$filter
,
self
::
UPDATE
,
$options
,
array
(
'$set'
=>
$update
));
}
/* }}} */
function
updateMany
(
array
$filter
,
$update
,
array
$options
=
array
())
{
/* {{{ */
return
$this
->
_writeSingle
(
$filter
,
self
::
UPDATE
,
$options
+
array
(
"limit"
=>
0
),
$update
);
}
/* }}} */
...
...
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