1

I am trying to install the mongoDB extension for PHP with MAMP so I can potentially access my MongoDB server, and as far as I can tell, I have done everything right, yet I am still getting errors.

I have the MongoDB extension installed - I can tell because:

$sudo pecl install mongodb
pecl/mongodb is already installed and is the same as the released version 1.5.3
install failed

Also my phpinfo shows this:

php mongodb extension

Also I have included the following:

var_dump(extension_loaded('mongodb'));
echo phpversion('mongodb')."\n";

which have returned:

/Applications/MAMP/htdocs/mongo.php:35:boolean true
1.5.3 

I also have:

$ composer require mongodb/mongodb
Using version ^1.4 for mongodb/mongodb
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files

phpinfo tells me my php.ini file is here:

location of php ini file

And i have added to that:

extension=mongodb.so

In my PHP file I have the following:

require 'vendor/autoload.php'; // include Composer's autoloader
$m = new MongoDB\Driver\Manager("mongodb://localhost:27017");
//$m = new MongoDB\Client("mongodb://localhost:27017");

echo "connected successfully";

// select a database
$db = $m->bob;
echo "database selected";

If I try the MongDB/Client option, I get the following error:

Fatal error: Uncaught Error: Class 'MongoDB\Client' not found in /Applications/MAMP/htdocs/mongo.php on line 61

If I try the MongoDB/Driver option, I get the following error:

Notice: Undefined property: MongoDB\Driver\Manager::$bob in /Applications/MAMP/htdocs/mongo.php on line 52

A var_dump of MongoDB\Driver etc. gives the following:

 /Applications/MAMP/htdocs/mongo.php:38:
 object(MongoDB\Driver\Manager)[3]
 public 'uri' => string 'mongodb://localhost:27017' (length=25)
 public 'cluster' => 
    array (size=0)
    empty

Is there anything I could be missing?

Weirdali
  • 413
  • 1
  • 7
  • 16

1 Answers1

0

have you added extension=mongodb.so to your php.ini file ?

that is the only information i do not see listed here.

Lars Hendriks
  • 998
  • 5
  • 22
  • Yes, sorry, I have that as well. I will add the info about that above. – Weirdali Oct 05 '18 at 12:16
  • could you try mongo.so instead of mongodb.so. it might help ( diffently not sure) – Lars Hendriks Oct 05 '18 at 12:21
  • Isn't that deprecated? mongodb then disappears from my phpinfo and it now says Class 'MongoDB\Driver\Manager' not found. – Weirdali Oct 05 '18 at 12:24
  • oh yes. (forgot to look at mongodb version) then i cant help you further i think. maybe try a guide or something to follow and create a testproject so you can compare the one that works vs this one. – Lars Hendriks Oct 05 '18 at 13:20
  • Not sure if allowed but I have tried some alternate code and I believe this is a step further but have a new problem, which I have asked here: https://stackoverflow.com/questions/52669717/mongodb-exception-server-reports-wire-version-0-but-version-of-libmongoc-requi – Weirdali Oct 05 '18 at 16:21