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
a32ac4f7
Commit
a32ac4f7
authored
Apr 10, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-45: List collections according to wire protocol version
parent
a20fa27a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
14 deletions
+18
-14
Database.php
src/Database.php
+18
-14
No files found.
src/Database.php
View file @
a32ac4f7
...
@@ -8,6 +8,7 @@ use MongoDB\Driver\Cursor;
...
@@ -8,6 +8,7 @@ use MongoDB\Driver\Cursor;
use
MongoDB\Driver\Manager
;
use
MongoDB\Driver\Manager
;
use
MongoDB\Driver\Query
;
use
MongoDB\Driver\Query
;
use
MongoDB\Driver\ReadPreference
;
use
MongoDB\Driver\ReadPreference
;
use
MongoDB\Driver\Server
;
use
MongoDB\Driver\WriteConcern
;
use
MongoDB\Driver\WriteConcern
;
use
MongoDB\Model\CollectionInfoIterator
;
use
MongoDB\Model\CollectionInfoIterator
;
use
MongoDB\Model\CollectionInfoCommandIterator
;
use
MongoDB\Model\CollectionInfoCommandIterator
;
...
@@ -97,8 +98,15 @@ class Database
...
@@ -97,8 +98,15 @@ class Database
*/
*/
public
function
listCollections
(
array
$options
=
array
())
public
function
listCollections
(
array
$options
=
array
())
{
{
// TODO: Determine if command or legacy method should be used
$readPreference
=
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
);
return
$this
->
listCollectionsCommand
(
$options
);
$server
=
$this
->
manager
->
selectServer
(
$readPreference
);
$serverInfo
=
$server
->
getInfo
();
$maxWireVersion
=
isset
(
$serverInfo
[
'maxWireVersion'
])
?
$serverInfo
[
'maxWireVersion'
]
:
0
;
return
(
$maxWireVersion
>=
3
)
?
$this
->
listCollectionsCommand
(
$server
,
$options
)
:
$this
->
listCollectionsLegacy
(
$server
,
$options
);
}
}
/**
/**
...
@@ -125,16 +133,14 @@ class Database
...
@@ -125,16 +133,14 @@ class Database
* Returns information for all collections in this database using the
* Returns information for all collections in this database using the
* listCollections command.
* listCollections command.
*
*
* @param array $options
* @param Server $server
* @param array $options
* @return CollectionInfoCommandIterator
* @return CollectionInfoCommandIterator
*/
*/
private
function
listCollectionsCommand
(
array
$options
=
array
())
private
function
listCollectionsCommand
(
Server
$server
,
array
$options
=
array
())
{
{
$command
=
new
Command
(
array
(
'listCollections'
=>
1
)
+
$options
);
$command
=
new
Command
(
array
(
'listCollections'
=>
1
)
+
$options
);
// TODO: Relax RP if connected to a secondary node in standalone mode
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
$command
);
$readPreference
=
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
);
$cursor
=
$this
->
manager
->
executeCommand
(
$this
->
databaseName
,
$command
,
$readPreference
);
return
new
CollectionInfoCommandIterator
(
$cursor
);
return
new
CollectionInfoCommandIterator
(
$cursor
);
}
}
...
@@ -143,13 +149,14 @@ class Database
...
@@ -143,13 +149,14 @@ class Database
* Returns information for all collections in this database by querying
* Returns information for all collections in this database by querying
* the "system.namespaces" collection (MongoDB <2.8).
* the "system.namespaces" collection (MongoDB <2.8).
*
*
* @param array $options
* @param Server $server
* @param array $options
* @return CollectionInfoLegacyIterator
* @return CollectionInfoLegacyIterator
* @throws InvalidArgumentException if the filter option is neither an array
* @throws InvalidArgumentException if the filter option is neither an array
* nor object, or if filter.name is not a
* nor object, or if filter.name is not a
* string.
* string.
*/
*/
private
function
listCollectionsLegacy
(
array
$options
=
array
())
private
function
listCollectionsLegacy
(
Server
$server
,
array
$options
=
array
())
{
{
$filter
=
array_key_exists
(
'filter'
,
$options
)
?
$options
[
'filter'
]
:
array
();
$filter
=
array_key_exists
(
'filter'
,
$options
)
?
$options
[
'filter'
]
:
array
();
...
@@ -167,10 +174,7 @@ class Database
...
@@ -167,10 +174,7 @@ class Database
$namespace
=
$this
->
databaseName
.
'.system.namespaces'
;
$namespace
=
$this
->
databaseName
.
'.system.namespaces'
;
$query
=
new
Query
(
$filter
);
$query
=
new
Query
(
$filter
);
// TODO: Relax RP if connected to a secondary node in standalone mode
$cursor
=
$server
->
executeQuery
(
$namespace
,
$query
);
$readPreference
=
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
);
$cursor
=
$this
->
manager
->
executeQuery
(
$namespace
,
$query
,
$readPreference
);
return
new
CollectionInfoLegacyIterator
(
$cursor
);
return
new
CollectionInfoLegacyIterator
(
$cursor
);
}
}
...
...
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