top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

"explain" with the new PHP driver and MongoDB 3.2?

+1 vote
557 views

I recently upgraded the latest PHP driver and could do an "explain" query by using the "$explain" modifier when executing the query, however as of MongoDB 3.2 the operator was removed so this is no longer possible.

So my question is how can I do an explain query with the new driver and MongoDB 3.2?

posted Apr 12, 2016 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

explain is a command in MongoDB, so you can use the generic "executeCommand" method on the Manager to run explain:

http://php.net/manual/en/mongodb-driver-manager.executecommand.php

Something like:

$cmd = [
 'explain' => [
 'find' => 'collectionname',
 'filter' => [ // your query
 'name' => 'Derick'
 ],
  ¦ "everything else from https://docs.mongodb.org/manual/reference/command/find/" ¦
 ]
];

$manager->executeCommand( 'databasename', $cmd );
answer Apr 12, 2016 by Ahmed Patel
Similar Questions
+2 votes

I am new to mongodb but I know php so I want to implement both and develop a single page application using php and mongoDB.A sample code will be helpful for me like.CRUD Operation

0 votes

is it possible to create views using the Node.js MongoDB Driver (3.0)? There is no db.createView() in the drivers API reference.

+1 vote

Can we connect to MongoDB Server 2.6.12 using Java Driver version 0.11? We have a constraint of upgrading Java Driver version which would require huge change in our client code. We use JDK 8 for compilation of our project. We would like to know whether it is possible to connect to MongoDB Server 2.6.12 or MongoDB Server 3.0 using Java Driver version 0.11 if we only use the limited set of features (not the functionalities that were introduced in Server version 2.6.12 or 3.0).

0 votes

We recently starting using MongoDB and the new Scala driver library (v 1.1.1). We have not made any custom configurations but we are consistently running out of connections and getting connection timeouts. I worry that we are using the driver incorrectly.

Please see my questions below -

  1. We are using dependency injection to manage the MongoClient. Should be injecting MongoClient or MongoDatabase into all of our CRUD classes?
  2. Should we treat the MongoClient and/or the MongoDatabase as a singleton?
  3. Are there any other common mistakes people have seen with the Scala driver?

Thanks in advance...

...