Get the App
SLTechnology News&Howtos  ›  Database  › 

About mongodb rollover MySQL

Shulou Source: shulou.com Published: 2022-06-01 16:11:33 11月01日 Update

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.

Tags: Data representatives databases fields files accounts questions sorting that is quantity ports thorny special two memory ascending parameters only can pass address Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft macOS Shulou Technology OPPO Reno Linux