ludo1960 Posted May 17, 2019 Share Posted May 17, 2019 (edited) Hello guys, I've installed the mongoDB PHP driver using "sudo pecl install mongodb" Testing shows driver is installed correctly and it appears nicely in phpinfo(): ludo@aegir:~$ php7.2 -i | grep -i mongodb mongodb MongoDB support => enabled MongoDB extension version => 1.5.3 MongoDB extension stability => stable mongodb.debug => no value => no value For connecting I've got: $db = new MongoDB\Driver\Manager("mongodb://localhost:27017"); Now I want to define a collection and insert a record, i've been using code from here https://www.php.net/manual/en/set.mongodb.php: $collection = $db->mydatabase->mytable; $result = $collection->insertOne( [ 'name' => 'test', 'item' => 'testitem' ] ); But this fails Notice: Undefined property: MongoDB\Driver\Manager::$mydatabase in /var/www.... Has anyone got a workingg example of defining and inserting into mongoDB. Seems the driver was updated fairly recently and so stuff on the internet is not always relevant. Edited May 17, 2019 by ludo1960 Quote Link to comment Share on other sites More sharing options...
ginerjm Posted May 17, 2019 Share Posted May 17, 2019 unfamiliar with Mongodb so this may be a silly question but what is this line saying: $db = new MongoDB\Driver\Manager("mongodb://localhost:27017"); Is "MongoDB\Driver\Manager" a function name that is part of the mongodb interface? To me it looks more like a path (without quotes) so I am puzzled. Quote Link to comment Share on other sites More sharing options...
gw1500se Posted May 17, 2019 Share Posted May 17, 2019 Mongo has its own PHP classes. Is this what you are using? Quote Link to comment Share on other sites More sharing options...
ludo1960 Posted May 17, 2019 Author Share Posted May 17, 2019 Hi there, Thats the old driver, i'm using the new one here: https://www.php.net/manual/en/set.mongodb.php Quote Link to comment Share on other sites More sharing options...
ludo1960 Posted May 17, 2019 Author Share Posted May 17, 2019 3 hours ago, ginerjm said: unfamiliar with Mongodb so this may be a silly question but what is this line saying: $db = new MongoDB\Driver\Manager("mongodb://localhost:27017"); Is "MongoDB\Driver\Manager" a function name that is part of the mongodb interface? To me it looks more like a path (without quotes) so I am puzzled. Sorry, the link is here https://www.php.net/manual/en/set.mongodb.php there is our chum MongDB\Driver\Manager . Quote Link to comment Share on other sites More sharing options...
gw1500se Posted May 18, 2019 Share Posted May 18, 2019 It looks to me like you want client not manager. In any case have you verified the path? You should be checking $db to make sure it is set. Quote Link to comment Share on other sites More sharing options...
ludo1960 Posted May 21, 2019 Author Share Posted May 21, 2019 (edited) Thanks for advice, wasn't getting anywhere till I found this https://www.php.net/manual/en/mongodb.tutorial.library.php now it works a treat, Once installed, you have access to all the mongo goodies https://docs.mongodb.com/php-library/current/ MongoDB\Client was indeed correct! Thanks again! Edited May 21, 2019 by ludo1960 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.