PHP Driver getIndexInfo

20 views
Skip to first unread message

tpneumat

unread,
Sep 23, 2016, 8:11:29 AM9/23/16
to mongodb-user
I am upgrading from MMAPV1 to Wiredtiger on mongo 3.2.9.  I am using the mongodb/mongo-php-driver.git drivers and cannot upgrade at this time.  I need a way to get a list of indexes like I could with $collection->getIndexInfo() in MMAPV1.  How can this be done?

Thanks Jeremy

tpneumat

unread,
Sep 23, 2016, 8:20:06 AM9/23/16
to mongodb-user
Sorry, I meant mongo-php-driver-legacy 1.4.4 to be exact

Jeremy Mikola

unread,
Sep 23, 2016, 11:21:15 AM9/23/16
to mongod...@googlegroups.com
On Fri, Sep 23, 2016 at 8:11 AM, tpneumat <jer...@dilltree.com> wrote:
I am upgrading from MMAPV1 to Wiredtiger on mongo 3.2.9.  I am using the mongodb/mongo-php-driver.git drivers and cannot upgrade at this time.  I need a way to get a list of indexes like I could with $collection->getIndexInfo() in MMAPV1.  How can this be done?

Since 3.0, the server implements a listIndexes command. This is particularly necessary for WiredTiger, since it doesn't have the same system collections as MMAPv1.

In the legacy PHP driver, you'll want to execute this command via MongoDB::command(). Since the command returns a cursor instead of inline results, the result document will need to be passed on to MongoCommandCursor::createFromDocument(), which will construct a MongoCommandCursor that you can then iterate.

tpneumat

unread,
Sep 23, 2016, 4:19:53 PM9/23/16
to mongodb-user
Thank you, Thank you!  I did it without the MongoCommandCursor::createFromDocument().  I just did this.

$res=$db->command(array("listIndexes" => $collection));
$tmp=$res['cursor']['firstBatch'];
foreach($tmp AS $i) $indexes[]=$i['name'];

Is there any problem with that?

Best ~ jeremy

Jeremy Mikola

unread,
Sep 26, 2016, 2:30:59 AM9/26/16
to mongod...@googlegroups.com


On Friday, September 23, 2016, tpneumat <jer...@dilltree.com> wrote:
Thank you, Thank you!  I did it without the MongoCommandCursor::createFromDocument().  I just did this.

$res=$db->command(array("listIndexes" => $collection));
$tmp=$res['cursor']['firstBatch'];
foreach($tmp AS $i) $indexes[]=$i['name'];

Is there any problem with that?

If there is not a cursor ID in the response document, you can trust that all results are in that "firstBatch" field. MongoCommandCursor handles iterating through all batches as necessary, which is why it's the suggested approach. 
Reply all
Reply to author
Forward
0 new messages