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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
8f9c54a1
Commit
8f9c54a1
authored
Feb 18, 2014
by
Alexander Mohorev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add method findOne() to the Collection class
parent
75ea33ac
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
2 deletions
+15
-2
Collection.php
extensions/mongodb/Collection.php
+15
-2
No files found.
extensions/mongodb/Collection.php
View file @
8f9c54a1
...
...
@@ -260,6 +260,18 @@ class Collection extends Object
}
/**
* Returns a a single document.
* @param array $condition query condition
* @param array $fields fields to be selected
* @return array|null the single document. Null is returned if the query results in nothing.
* @see http://www.php.net/manual/en/mongocollection.findone.php
*/
public
function
findOne
(
$condition
=
[],
$fields
=
[])
{
return
$this
->
mongoCollection
->
findOne
(
$this
->
buildCondition
(
$condition
),
$fields
);
}
/**
* Inserts new data into collection.
* @param array|object $data data to be inserted.
* @param array $options list of options in format: optionName => optionValue.
...
...
@@ -372,11 +384,12 @@ class Collection extends Object
* @param array $options list of options in format: optionName => optionValue.
* @return integer|boolean number of updated documents or whether operation was successful.
* @throws Exception on failure.
* @see http://www.php.net/manual/en/mongocollection.remove.php
*/
public
function
remove
(
$condition
=
[],
$options
=
[])
{
$condition
=
$this
->
buildCondition
(
$condition
);
$options
=
array_merge
([
'w'
=>
1
,
'
multiple'
=>
tru
e
],
$options
);
$options
=
array_merge
([
'w'
=>
1
,
'
justOne'
=>
fals
e
],
$options
);
$token
=
$this
->
composeLogToken
(
'remove'
,
[
$condition
,
$options
]);
Yii
::
info
(
$token
,
__METHOD__
);
try
{
...
...
@@ -522,7 +535,7 @@ class Collection extends Object
* Argument will be automatically cast to [[\MongoCode]].
* @param string|array $out output collection name. It could be a string for simple output
* ('outputCollection'), or an array for parametrized output (['merge' => 'outputCollection']).
* You can pass ['inline' => true] to fetch the result at once without temporary collection usage.
* You can pass ['inline' => true] to fetch the result at once without temporary collection usage.
* @param array $condition criteria for including a document in the aggregation.
* @param array $options additional optional parameters to the mapReduce command. Valid options include:
* - sort - array - key to sort the input documents. The sort key must be in an existing index for this collection.
...
...
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