Comparison of MongoClient and MongoDB. Why is MongoClient better?

I don't like the new mongo, MongoDB requires several libs in PHP7.

MongoClient (deprecated) in php 5 is much more convenient and easier!

I decided to run a script and compare the two versions, and the results are pretty amazing:

MongoDB (PHP 7.0.2)

$client = new MongoDB\Client( 'mongodb://root: password@localhost :port', ['readPreference' => 'secondaryPreferred'] ); $db = $client->selectDatabase('namedb'); $collection = $client->selectCollection('namedb', 'test'); $document = $collection->findOne(['_id' => 'works']); var_dump($document); $time = microtime(); $time = explode(' ', $time); $time = $time[1] + $time[0]; $finish = $time; $total_time = round(($finish - $start), 4); echo '<br><br>Page generated in ' . $total_time . ' seconds.'; 

Mongo / MongoClient (PHP 5.6.17)

 $db = new MongoClient('mongodb://root: password@localhost :port'); $c = $db->namedb->test; $a = $c->findOne(array("_id" => 'works')); var_dump($a); $time = microtime(); $time = explode(' ', $time); $time = $time[1] + $time[0]; $finish = $time; $total_time = round(($finish - $start), 4); echo '<br><br>Page generated in ' . $total_time . ' seconds.'; 

Comparison of MongoClient (PHP 7.0.2) and MongoDB (PHP 5.6.17)

Anyone else having this problem? I can not find any benefit in using the new version of MongoDB, all the problems!

+5
source share
1 answer

MongoClient is a native driver written as an extension of PHP.

MongoDB is PHP code that uses a different PHP extension. I assume the new extension is easier to maintain, as it shares the libmongoc library used by projects other than PHP.

Comparing the native driver with the PHP library is an unfair comparison. If you want to compare performance, you should try one native driver directly opposite the other.

I can not find any benefit in using the new version of MongoDB

First of all, the obsolete MongoClient extension MongoClient deprecated. He will live only when you or others choose him and support him. Although having two similar libraries for the same task will be confusing (see Mysql vs mysqli).

MongoDB designed to provide a higher level of abstraction, and you can probably expect more frequent feature updates than your own driver.

0
source

Source: https://habr.com/ru/post/1242016/


All Articles