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
70f8c0a1
Commit
70f8c0a1
authored
Feb 06, 2018
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #485
parents
d9c277ad
0b511a05
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
84 additions
and
1 deletion
+84
-1
apiargs-MongoDBClient-method-listDatabases-option.yaml
...es/apiargs-MongoDBClient-method-listDatabases-option.yaml
+14
-0
apiargs-MongoDBDatabase-method-listCollections-option.yaml
...piargs-MongoDBDatabase-method-listCollections-option.yaml
+6
-1
ListCollections.php
src/Operation/ListCollections.php
+4
-0
ListDatabases.php
src/Operation/ListDatabases.php
+12
-0
ListDatabasesFunctionalTest.php
tests/Operation/ListDatabasesFunctionalTest.php
+44
-0
ListDatabasesTest.php
tests/Operation/ListDatabasesTest.php
+4
-0
No files found.
docs/includes/apiargs-MongoDBClient-method-listDatabases-option.yaml
View file @
70f8c0a1
arg_name
:
option
name
:
filter
type
:
array|object
description
:
|
A query expression to filter the list of databases.
You can specify a query expression for database fields (e.g. ``name``,
``sizeOnDisk``, ``empty``).
.. versionadded:: 1.3
interface
:
phpmethod
operation
:
~
optional
:
true
---
source
:
source
:
file
:
apiargs-common-option.yaml
file
:
apiargs-common-option.yaml
ref
:
maxTimeMS
ref
:
maxTimeMS
...
...
docs/includes/apiargs-MongoDBDatabase-method-listCollections-option.yaml
View file @
70f8c0a1
...
@@ -4,7 +4,12 @@ type: array|object
...
@@ -4,7 +4,12 @@ type: array|object
description
:
|
description
:
|
A query expression to filter the list of collections.
A query expression to filter the list of collections.
You can specify a query expression on the collection ``name`` and ``options``.
You can specify a query expression for collection fields (e.g. ``name``,
``options``).
For server versions < 3.0, the filter can only be used to match the ``name``
field with a string value. More complex filters will result in an exception at
execution time if used.
interface
:
phpmethod
interface
:
phpmethod
operation
:
~
operation
:
~
optional
:
true
optional
:
true
...
...
src/Operation/ListCollections.php
View file @
70f8c0a1
...
@@ -49,6 +49,10 @@ class ListCollections implements Executable
...
@@ -49,6 +49,10 @@ class ListCollections implements Executable
*
*
* * filter (document): Query by which to filter collections.
* * filter (document): Query by which to filter collections.
*
*
* For server versions < 3.0, the filter can only be used to match the
* "name" field with a string value. More complex filters will result in
* an exception at execution time if used.
*
* * maxTimeMS (integer): The maximum amount of time to allow the query to
* * maxTimeMS (integer): The maximum amount of time to allow the query to
* run.
* run.
*
*
...
...
src/Operation/ListDatabases.php
View file @
70f8c0a1
...
@@ -42,6 +42,10 @@ class ListDatabases implements Executable
...
@@ -42,6 +42,10 @@ class ListDatabases implements Executable
*
*
* Supported options:
* Supported options:
*
*
* * filter (document): Query by which to filter databases.
*
* For servers < 3.6, this option is ignored.
*
* * maxTimeMS (integer): The maximum amount of time to allow the query to
* * maxTimeMS (integer): The maximum amount of time to allow the query to
* run.
* run.
*
*
...
@@ -54,6 +58,10 @@ class ListDatabases implements Executable
...
@@ -54,6 +58,10 @@ class ListDatabases implements Executable
*/
*/
public
function
__construct
(
array
$options
=
[])
public
function
__construct
(
array
$options
=
[])
{
{
if
(
isset
(
$options
[
'filter'
])
&&
!
is_array
(
$options
[
'filter'
])
&&
!
is_object
(
$options
[
'filter'
]))
{
throw
InvalidArgumentException
::
invalidType
(
'"filter" option'
,
$options
[
'filter'
],
'array or object'
);
}
if
(
isset
(
$options
[
'maxTimeMS'
])
&&
!
is_integer
(
$options
[
'maxTimeMS'
]))
{
if
(
isset
(
$options
[
'maxTimeMS'
])
&&
!
is_integer
(
$options
[
'maxTimeMS'
]))
{
throw
InvalidArgumentException
::
invalidType
(
'"maxTimeMS" option'
,
$options
[
'maxTimeMS'
],
'integer'
);
throw
InvalidArgumentException
::
invalidType
(
'"maxTimeMS" option'
,
$options
[
'maxTimeMS'
],
'integer'
);
}
}
...
@@ -78,6 +86,10 @@ class ListDatabases implements Executable
...
@@ -78,6 +86,10 @@ class ListDatabases implements Executable
{
{
$cmd
=
[
'listDatabases'
=>
1
];
$cmd
=
[
'listDatabases'
=>
1
];
if
(
!
empty
(
$this
->
options
[
'filter'
]))
{
$cmd
[
'filter'
]
=
(
object
)
$this
->
options
[
'filter'
];
}
if
(
isset
(
$this
->
options
[
'maxTimeMS'
]))
{
if
(
isset
(
$this
->
options
[
'maxTimeMS'
]))
{
$cmd
[
'maxTimeMS'
]
=
$this
->
options
[
'maxTimeMS'
];
$cmd
[
'maxTimeMS'
]
=
$this
->
options
[
'maxTimeMS'
];
}
}
...
...
tests/Operation/ListDatabasesFunctionalTest.php
View file @
70f8c0a1
...
@@ -2,12 +2,56 @@
...
@@ -2,12 +2,56 @@
namespace
MongoDB\Tests\Operation
;
namespace
MongoDB\Tests\Operation
;
use
MongoDB\Operation\InsertOne
;
use
MongoDB\Operation\ListDatabases
;
use
MongoDB\Operation\ListDatabases
;
use
MongoDB\Tests\CommandObserver
;
use
MongoDB\Tests\CommandObserver
;
use
stdClass
;
use
stdClass
;
class
ListDatabasesFunctionalTest
extends
FunctionalTestCase
class
ListDatabasesFunctionalTest
extends
FunctionalTestCase
{
{
public
function
testListDatabases
()
{
$server
=
$this
->
getPrimaryServer
();
$insertOne
=
new
InsertOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'x'
=>
1
]);
$writeResult
=
$insertOne
->
execute
(
$server
);
$this
->
assertEquals
(
1
,
$writeResult
->
getInsertedCount
());
$operation
=
new
ListDatabases
();
$databases
=
$operation
->
execute
(
$server
);
$this
->
assertInstanceOf
(
'MongoDB\Model\DatabaseInfoIterator'
,
$databases
);
foreach
(
$databases
as
$database
)
{
$this
->
assertInstanceOf
(
'MongoDB\Model\DatabaseInfo'
,
$database
);
}
}
public
function
testFilterOption
()
{
if
(
version_compare
(
$this
->
getServerVersion
(),
'3.6.0'
,
'<'
))
{
$this
->
markTestSkipped
(
'listDatabase command "filter" option is not supported'
);
}
$server
=
$this
->
getPrimaryServer
();
$insertOne
=
new
InsertOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'x'
=>
1
]);
$writeResult
=
$insertOne
->
execute
(
$server
);
$this
->
assertEquals
(
1
,
$writeResult
->
getInsertedCount
());
$operation
=
new
ListDatabases
([
'filter'
=>
[
'name'
=>
$this
->
getDatabaseName
()]]);
$databases
=
$operation
->
execute
(
$server
);
$this
->
assertInstanceOf
(
'MongoDB\Model\DatabaseInfoIterator'
,
$databases
);
$this
->
assertCount
(
1
,
$databases
);
foreach
(
$databases
as
$database
)
{
$this
->
assertInstanceOf
(
'MongoDB\Model\DatabaseInfo'
,
$database
);
$this
->
assertEquals
(
$this
->
getDatabaseName
(),
$database
->
getName
());
}
}
public
function
testSessionOption
()
public
function
testSessionOption
()
{
{
if
(
version_compare
(
$this
->
getServerVersion
(),
'3.6.0'
,
'<'
))
{
if
(
version_compare
(
$this
->
getServerVersion
(),
'3.6.0'
,
'<'
))
{
...
...
tests/Operation/ListDatabasesTest.php
View file @
70f8c0a1
...
@@ -19,6 +19,10 @@ class ListDatabasesTest extends TestCase
...
@@ -19,6 +19,10 @@ class ListDatabasesTest extends TestCase
{
{
$options
=
[];
$options
=
[];
foreach
(
$this
->
getInvalidDocumentValues
()
as
$value
)
{
$options
[][]
=
[
'filter'
=>
$value
];
}
foreach
(
$this
->
getInvalidIntegerValues
()
as
$value
)
{
foreach
(
$this
->
getInvalidIntegerValues
()
as
$value
)
{
$options
[][]
=
[
'maxTimeMS'
=>
$value
];
$options
[][]
=
[
'maxTimeMS'
=>
$value
];
}
}
...
...
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