This article is to share with you about how to upgrade PHP7 operation MongoDB Method Introduction, the content is very reference value, hope can help the need for small partners.
Objective
There are many users who use Php+mongodb because MongoDB is convenient for storing unstructured data. In PHP5 and before, the official provided two extensions, Mongo
and MongoDB
, among them, the Mongo
classes based on a number of MongoClient
core classes to operate, encapsulation is very convenient, so basically will choose the Mongo
extension.
But with PHP5 upgrading to PHP7, the official no longer supports Mongo extensions, only MongoDB, and PHP7 's performance gains are huge. So that people can not give up, so how to replace Mongo into MongoDB becomes a problem to be solved urgently. MongoDB introduces namespaces, but the functional encapsulation is very poor, if it is not to use the native extension, it almost means to write the native Mongo statement. This idea is contrary to the ORM simplification IO
of the syntax problems brought about by the DB operation and focus on the logic optimization idea.
In this case, MONGODB official could not help, in order to facilitate the use, increase market share, the introduction of the MongoDB-based expansion of the library:
MongoDB Driver
If the original driver is used, the approximate syntax is as follows:
<?phpuse mongodb\driver\manager;use mongodb\driver\bulkwrite;use mongodb\driver\writeconcern;use MongoDB\Driver \query;use Mongodb\driver\command;class MongoDB {
Related recommendations:
Introduction to User usage in Yii2 (code attached)
Development of composer extensions and application of Laravel framework