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
0ff26cd8
Commit
0ff26cd8
authored
Nov 30, 2016
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-238: Implement Bucket::findOne() method
parent
78e69811
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
138 additions
and
0 deletions
+138
-0
apiargs-MongoDBGridFSBucket-method-findOne-option.yaml
...es/apiargs-MongoDBGridFSBucket-method-findOne-option.yaml
+42
-0
MongoDBGridFSBucket.txt
docs/reference/class/MongoDBGridFSBucket.txt
+1
-0
MongoDBGridFSBucket-find.txt
docs/reference/method/MongoDBGridFSBucket-find.txt
+1
-0
MongoDBGridFSBucket-findOne.txt
docs/reference/method/MongoDBGridFSBucket-findOne.txt
+46
-0
Bucket.php
src/GridFS/Bucket.php
+14
-0
CollectionWrapper.php
src/GridFS/CollectionWrapper.php
+12
-0
BucketFunctionalTest.php
tests/GridFS/BucketFunctionalTest.php
+22
-0
No files found.
docs/includes/apiargs-MongoDBGridFSBucket-method-findOne-option.yaml
0 → 100644
View file @
0ff26cd8
source
:
file
:
apiargs-MongoDBCollection-method-find-option.yaml
ref
:
projection
---
source
:
file
:
apiargs-MongoDBCollection-method-find-option.yaml
ref
:
sort
---
source
:
file
:
apiargs-MongoDBCollection-method-find-option.yaml
ref
:
skip
---
source
:
file
:
apiargs-MongoDBCollection-common-option.yaml
ref
:
collation
---
source
:
file
:
apiargs-MongoDBCollection-method-find-option.yaml
ref
:
comment
---
source
:
file
:
apiargs-common-option.yaml
ref
:
maxTimeMS
---
source
:
file
:
apiargs-MongoDBCollection-method-find-option.yaml
ref
:
readConcern
---
source
:
file
:
apiargs-MongoDBGridFSBucket-method-find-option.yaml
ref
:
readPreference
---
source
:
file
:
apiargs-MongoDBGridFSBucket-method-find-option.yaml
ref
:
typeMap
post
:
|
This will be used for the returned result document.
---
source
:
file
:
apiargs-MongoDBCollection-method-find-option.yaml
ref
:
modifiers
...
docs/reference/class/MongoDBGridFSBucket.txt
View file @
0ff26cd8
...
...
@@ -40,6 +40,7 @@ Methods
/reference/method/MongoDBGridFSBucket-downloadToStreamByName
/reference/method/MongoDBGridFSBucket-drop
/reference/method/MongoDBGridFSBucket-find
/reference/method/MongoDBGridFSBucket-findOne
/reference/method/MongoDBGridFSBucket-getBucketName
/reference/method/MongoDBGridFSBucket-getDatabaseName
/reference/method/MongoDBGridFSBucket-getFileDocumentForStream
...
...
docs/reference/method/MongoDBGridFSBucket-find.txt
View file @
0ff26cd8
...
...
@@ -40,3 +40,4 @@ See Also
--------
- :phpmethod:`MongoDB\\Collection::find()`
- :phpmethod:`MongoDB\\GridFS\\Bucket::findOne()`
docs/reference/method/MongoDBGridFSBucket-findOne.txt
0 → 100644
View file @
0ff26cd8
==================================
MongoDB\\GridFS\\Bucket::findOne()
==================================
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
Definition
----------
.. phpmethod:: MongoDB\\GridFS\\Bucket::findOne()
Finds a single document from the GridFS bucket's files collection matching
the query.
.. code-block:: php
function findOne($filter = [], array $options = []): array|object|null
This method has the following parameters:
.. include:: /includes/apiargs/MongoDBCollection-method-findOne-param.rst
The ``$options`` parameter supports the following options:
.. include:: /includes/apiargs/MongoDBGridFSBucket-method-findOne-option.rst
Return Values
-------------
An array or object for the :term:`first document <natural order>` that matched
the query, or ``null`` if no document matched the query. The return type will
depend on the ``typeMap`` option.
.. todo: add examples
See Also
--------
- :phpmethod:`MongoDB\\Collection::findOne()`
- :phpmethod:`MongoDB\\GridFS\\Bucket::find()`
src/GridFS/Bucket.php
View file @
0ff26cd8
...
...
@@ -223,6 +223,20 @@ class Bucket
return
$this
->
collectionWrapper
->
findFiles
(
$filter
,
$options
);
}
/**
* Finds a single document from the GridFS bucket's files collection
* matching the query.
*
* @see FindOne::__construct() for supported options
* @param array|object $filter Query by which to filter documents
* @param array $options Additional options
* @return array|object|null
*/
public
function
findOne
(
$filter
=
[],
array
$options
=
[])
{
return
$this
->
collectionWrapper
->
findOneFile
(
$filter
,
$options
);
}
/**
* Return the bucket name.
*
...
...
src/GridFS/CollectionWrapper.php
View file @
0ff26cd8
...
...
@@ -140,6 +140,18 @@ class CollectionWrapper
return
$this
->
filesCollection
->
find
(
$filter
,
$options
);
}
/**
* Finds a single document from the GridFS bucket's files collection.
*
* @param array|object $filter Query by which to filter documents
* @param array $options Additional options
* @return array|object|null
*/
public
function
findOneFile
(
$filter
,
array
$options
=
[])
{
return
$this
->
filesCollection
->
findOne
(
$filter
,
$options
);
}
/**
* Return the bucket name.
*
...
...
tests/GridFS/BucketFunctionalTest.php
View file @
0ff26cd8
...
...
@@ -328,6 +328,28 @@ class BucketFunctionalTest extends FunctionalTestCase
$this
->
assertInstanceOf
(
'MongoDB\Model\BSONDocument'
,
$fileDocument
);
}
public
function
testFindOne
()
{
$this
->
bucket
->
uploadFromStream
(
'a'
,
$this
->
createStream
(
'foo'
));
$this
->
bucket
->
uploadFromStream
(
'b'
,
$this
->
createStream
(
'foobar'
));
$this
->
bucket
->
uploadFromStream
(
'c'
,
$this
->
createStream
(
'foobarbaz'
));
$fileDocument
=
$this
->
bucket
->
findOne
(
[
'length'
=>
[
'$lte'
=>
6
]],
[
'projection'
=>
[
'filename'
=>
1
,
'length'
=>
1
,
'_id'
=>
0
,
],
'sort'
=>
[
'length'
=>
-
1
],
]
);
$this
->
assertInstanceOf
(
'MongoDB\Model\BSONDocument'
,
$fileDocument
);
$this
->
assertSameDocument
([
'filename'
=>
'b'
,
'length'
=>
6
],
$fileDocument
);
}
public
function
testGetBucketNameWithCustomValue
()
{
$bucket
=
new
Bucket
(
$this
->
manager
,
$this
->
getDatabaseName
(),
[
'bucketName'
=>
'custom_fs'
]);
...
...
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