Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
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
PSDI Army
yii2
Commits
61cacdfc
Commit
61cacdfc
authored
Mar 04, 2014
by
Alexander Mohorev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add findAndModify() method to the Collection class
parent
90c7bf28
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
1 deletion
+27
-1
Collection.php
extensions/mongodb/Collection.php
+27
-1
No files found.
extensions/mongodb/Collection.php
View file @
61cacdfc
...
@@ -260,7 +260,7 @@ class Collection extends Object
...
@@ -260,7 +260,7 @@ class Collection extends Object
}
}
/**
/**
* Returns a
a
single document.
* Returns a single document.
* @param array $condition query condition
* @param array $condition query condition
* @param array $fields fields to be selected
* @param array $fields fields to be selected
* @return array|null the single document. Null is returned if the query results in nothing.
* @return array|null the single document. Null is returned if the query results in nothing.
...
@@ -272,6 +272,32 @@ class Collection extends Object
...
@@ -272,6 +272,32 @@ class Collection extends Object
}
}
/**
/**
* Updates a document and returns it.
* @param array $condition query condition
* @param array $update update criteria
* @param array $fields fields to be returned
* @param array $options list of options in format: optionName => optionValue.
* @return array|null the original document, or the modified document when $options['new'] is set.
* @throws Exception on failure.
* @see http://www.php.net/manual/en/mongocollection.findandmodify.php
*/
public
function
findAndModify
(
$condition
,
$update
,
$fields
=
[],
$options
=
[])
{
$condition
=
$this
->
buildCondition
(
$condition
);
$token
=
$this
->
composeLogToken
(
'findAndModify'
,
[
$condition
,
$update
,
$fields
,
$options
]);
Yii
::
info
(
$token
,
__METHOD__
);
try
{
Yii
::
beginProfile
(
$token
,
__METHOD__
);
$result
=
$this
->
mongoCollection
->
findAndModify
(
$condition
,
$update
,
$fields
,
$options
);
Yii
::
endProfile
(
$token
,
__METHOD__
);
return
$result
;
}
catch
(
\Exception
$e
)
{
Yii
::
endProfile
(
$token
,
__METHOD__
);
throw
new
Exception
(
$e
->
getMessage
(),
(
int
)
$e
->
getCode
(),
$e
);
}
}
/**
* Inserts new data into collection.
* Inserts new data into collection.
* @param array|object $data data to be inserted.
* @param array|object $data data to be inserted.
* @param array $options list of options in format: optionName => optionValue.
* @param array $options list of options in format: optionName => optionValue.
...
...
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