I want to get your recommend about my web project. I use PHP and MongoDB but I was confused when I read this sentence from php documentation.
This extension that defines this class is deprecated. Instead, the MongoDB extension should be used. Alternatives to this class include: MongoDB\Driver\Manager
I already used MongoClient Class for CRUD but after reading that sentence, I tried to migrate MongoClient to MongoDB\Driver\Manager. The connection using MongoDB\Driver\Manager was successed but I couldn't anymore :(
My PHP version is 5.6.29. Mongo extension version is 1.7.0 MongoDB extension version is 1.2.9
My questions are: Do I have to use MongoDB\Driver\Manager Class? Is it better than MongoClient Class?
Here is a good answer about deprecated language features: What does PHP do with deprecated functions?
And here is a proper usage for php with mongodb:
$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
$filter = [];
$options = [
'sort' => ['_id' => 1],
];
$query = new MongoDB\Driver\Query($filter, $options);
$cursor = $manager->executeQuery('db.collection', $query);
foreach ($cursor as $document) {
//...
}
There are are a lot of tutorials for CRUD operation with php and mongodb, for example: MongoDB PHP tutorial
In short: you should not use deprecated feature because of security reasons and because it could get removed from php in the future. So better update your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With