Years ago because of the company's business needs, the backstage need to get records, the need to run a script every day, the running records run into the storage inside, about 1 million per day, the database is MongoDB, considering a data entry, more than 1 million will run off, thinking of bulk input data, so fast, And the consumption system resources are also few, on the internet to find a lot of data on the mass insertion method, and finally found
Mongoclient provides a batchinsert function for batch additions!
Here is the usage and description of the Batchinsert function: http://php.net/manual/zh/mongocollection.batchinsert.php
<?PHP$users=Array(); for($i= 0;$i<100;$i++) {$users[] =Array(' username ' = ' user '.$i, ' I ' =$i); }$mongo=Newmongoclient (); $collection=$mongo->my_db->users; $collection-Batchinsert($users);
?>
Here's a simple code example that adds data in bulk.
Note: Here's $users format , Array (array (), Array (), array ());
MongoDB BULK INSERT Data