Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

About mongodb rollover MySQL

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Recently, some data from Mongodb needs to be transferred to MySQL. Previously, only BSON data packets were available.

The original idea, directly using PHP extension bson_decode,

Two thorny problems were identified,

One is the memory occupation problem, if a bson exceeds 2M, it seems to be very laborious. That is, although Chinese appears, there are still many special symbols that cannot be displayed. There are always problems

It is best to solve the problem from the source of the data. It should be much better to use json or csv to process it.

mongoexport

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

-h,--host: Represents the database address of the remote connection, and connects to the local Mongo database by default;

--port: represents the port of the database for remote connection, remote port 27017 for default connection;

-u,--username: represents the account connected to the remote database. If you set the authentication of the database, you need to specify the user account;

-p,--password: represents the password corresponding to the account connected to the database;

-d,--db: represents the database to which the connection is made;

-c,--collection: Represents a collection in a join database;

-f, --fields: represents the fields in the collection, and the exported fields can be selected according to the settings;

--type: represents the file type of export output, including csv and json files;

-o, --out: represents the exported file name;

-q, --query: represents query conditions;

--skip: skip a specified amount of data;

--limit: reads a specified number of data records;

--sort: sort data, you can specify the sorting field through the parameter, and use 1 and-1 to specify the sorting method, where 1 is for ascending order, and-1 is for descending order, such as sort({KEY:1}).

That's it. That's it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report