3

As we know, there is a new PHP 7 MongoDB driver, and lots of classes and functions are replaced by new ones. So can anyone give me a quick example of how to use MongoDB with PHP7 properly?

Will
  • 24,082
  • 14
  • 97
  • 108
Ashok
  • 2,411
  • 1
  • 13
  • 23

1 Answers1

-1

1) I advise you to use the PHP Library : https://github.com/mongodb/mongo-php-library

2) Here is some code I use to connect to DB / collection

$client = new MongoDB\Client("mongodb://USER:PASSWORD@localhost:27017/BaseName");
$collection = $client->BaseName->CollectionName;

3) Example of FindOne query :

$document = $collection->findOne(
            ['SomeField' => ''$var'']
            );

4) Check out the docs of the library here , they give a few examples. https://github.com/mongodb/mongo-php-library

Chuck
  • 98
  • 2
  • 10