MongoDB BULK INSERT Data

Source: Internet
Author: User
Tags bulk insert mongoclient

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.