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
e950daec
Commit
e950daec
authored
Apr 24, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-46: Index enumeration methods
parent
79d07ff7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
4 deletions
+48
-4
Collection.php
src/Collection.php
+48
-4
No files found.
src/Collection.php
View file @
e950daec
...
...
@@ -2,13 +2,16 @@
namespace
MongoDB
;
use
MongoDB\Driver\BulkWrite
;
use
MongoDB\Driver\Command
;
use
MongoDB\Driver\Cursor
;
use
MongoDB\Driver\Manager
;
use
MongoDB\Driver\Query
;
use
MongoDB\Driver\ReadPreference
;
use
MongoDB\Driver\
BulkWrite
;
use
MongoDB\Driver\
Server
;
use
MongoDB\Driver\WriteConcern
;
use
MongoDB\Model\IndexInfoIterator
;
use
MongoDB\Model\IndexInfoIteratorIterator
;
use
InvalidArgumentException
;
class
Collection
...
...
@@ -963,15 +966,23 @@ class Collection
}
/**
* Returns information for all indexes
in
the collection.
* Returns information for all indexes
for
the collection.
*
* @see http://docs.mongodb.org/manual/reference/command/listIndexes/
* @see http://docs.mongodb.org/manual/reference/method/db.collection.getIndexes/
* @return
Curs
or
* @return
IndexInfoIterat
or
*/
public
function
listIndexes
()
{
// TODO
$readPreference
=
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
);
$server
=
$this
->
manager
->
selectServer
(
$readPreference
);
$serverInfo
=
$server
->
getInfo
();
$maxWireVersion
=
isset
(
$serverInfo
[
'maxWireVersion'
])
?
$serverInfo
[
'maxWireVersion'
]
:
0
;
return
(
$maxWireVersion
>=
3
)
?
$this
->
listIndexesCommand
(
$server
)
:
$this
->
listIndexesLegacy
(
$server
);
}
/**
...
...
@@ -1150,4 +1161,37 @@ class Collection
$bulk
->
update
(
$filter
,
$update
,
$options
);
return
$this
->
manager
->
executeBulkWrite
(
$this
->
ns
,
$bulk
,
$this
->
wc
);
}
/**
* Returns information for all indexes for this collection using the
* listIndexes command.
*
* @see http://docs.mongodb.org/manual/reference/command/listIndexes/
* @param Server $server
* @return IndexInfoIteratorIterator
*/
private
function
listIndexesCommand
(
Server
$server
)
{
$command
=
new
Command
(
array
(
'listIndexes'
=>
$this
->
collname
));
$cursor
=
$server
->
executeCommand
(
$this
->
dbname
,
$command
);
$cursor
->
setTypeMap
(
array
(
'document'
=>
'array'
));
return
new
IndexInfoIteratorIterator
(
$cursor
);
}
/**
* Returns information for all indexes for this collection by querying the
* "system.indexes" collection (MongoDB <2.8).
*
* @param Server $server
* @return IndexInfoIteratorIterator
*/
private
function
listIndexesLegacy
(
Server
$server
)
{
$query
=
new
Query
(
array
(
'ns'
=>
$this
->
ns
));
$cursor
=
$server
->
executeQuery
(
$this
->
dbname
.
'.system.indexes'
,
$query
);
$cursor
->
setTypeMap
(
array
(
'document'
=>
'array'
));
return
new
IndexInfoIteratorIterator
(
$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