About MongoDB dump MySQL

Source: Internet
Author: User
Tags mongodb

The recent need to dump some of MONGODB data to MySQL, previously only bson packets.
The initial idea is to use PHP's extension bson_decode directly,
Found two tricky questions,

    1. One is the memory consumption problem, if a bson more than 2M, seems to be very laborious.
    2. It is Chinese although appeared, but there will be a lot of special symbols do not appear, always have problems

It's best to solve it from the data source, and it's much better to use JSON or CSV to handle it.
Mongoexport

mongoexport --port ***** -u **** -p ******** -d ****** -c ***** -f ******************************** --type=json -o *****.json

-H,--Host: Represents the database address of the remote connection, the local MONGO database is connected by default;
--port: The port that represents the remote connected database, the default connection for remote port 27017;
-U,--Username: Represents the account connected to the remote database, if you set up the database authentication, you need to specify user account;
-P,--Password: the password corresponding to the account connected to the database;
-D,--DB: Represents the connected database;
-C,--Collection: Represents a collection in a connected database;
-F,--fields: Represents the field in the collection, you can select the exported field according to the settings;
--type: Represents the exported output file types, including CSV and JSON files;
-O,--out: Represents the exported file name;
-Q,--query: represents the query criteria;
--skip: Skips a specified amount of data;
--limit: Reads a specified number of data records;
--sort: Sorting the data, you can specify the sorted fields by parameters, and use 1 and-one to specify how the sort is sorted, where 1 is in ascending order, and 1 is for descending order, such as sort ({key:1}).

Yes, that's it.

About MongoDB dump MySQL

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.