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,
- One is the memory consumption problem, if a bson more than 2M, seems to be very laborious.
- 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