Get the App
SLTechnology News&Howtos  ›  Database  › 

How to import Mysql data into MongoDB

Shulou Source: shulou.com Published: 2022-05-31 21:13:22 09月23日 Update

Today, I will talk to you about how to import Mysql data into MongoDB. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

(1) Export data bit csv files from mysql, such as:

Java code

SELECT * FROM APP_CALL_LOG_1362959187037 WHERE CREATE_TIME

< '2013-03-07 14:45:04' into outfile '/tmp/all_call_log_012.csv' fields terminated by ',' lines terminated by '\n';   (2)导入csv文件到mongodb,如:   Java代码   bin/mongoimport --host 114.112.94.104 --port 27017 -d lb_v1_log -c APP_CALL_LOG --type csv --ignoreBlanks -f ID,IP,URI,URL,D_CODE,D_TYPE,UID,APP_FROM,CREATE   _TIME,USER_AGENT,REMARK -file /usr/local/all_call_log_012.csv   (3)对导入数据矫正处理,如:   Java代码   pmy_log_rs:PRIMARY>

Db.APP_CALL_LOG.update ({UID: "\ N"}, {$set: {'UID': null}}, false,true)

Pmy_log_rs:PRIMARY > db.APP_CALL_LOG.update ({IP: "\ N"}, {$set: {'IP': null}}, false,true)

Pmy_log_rs:PRIMARY > db.APP_CALL_LOG.update ({D_TYPE: "\ N"}, {$set: {'Down typewriter: null}}, false,true)

Pmy_log_rs:PRIMARY > db.APP_CALL_LOG.update ({D_CODE: "\ N"}, {$set: {'Down codes: null}}, false,true)

Pmy_log_rs:PRIMARY > db.APP_CALL_LOG.update ({CREATE_TIME: "\ N"}, {$set: {'CREATE_TIME': null}}, false,true)

Pmy_log_rs:PRIMARY > db.APP_CALL_LOG.update ({APP_FROM: "\ N"}, {$set: {'APP_FROM': null}}, false,true)

Pmy_log_rs:PRIMARY > db.APP_CALL_LOG.update ({URI: "\ N"}, {$set: {'URI': null}}, false,true)

Pmy_log_rs:PRIMARY > db.APP_CALL_LOG.update ({URL: "\ N"}, {$set: {'URL': null}}, false,true)

Pmy_log_rs:PRIMARY > db.APP_CALL_LOG.update ({USER_AGENT: "\ N"}, {$set: {'USER_AGENT': null}}, false,true)

Pmy_log_rs:PRIMARY > db.APP_CALL_LOG.update ({REMARK: "\ N"}, {$set: {'REMARK': null}}, false,true)

(4) Field type correction, such as:

Java code

Db.APP_CALL_LOG.find ({}) .forEach (function (x) {x.D_CODE = "" + x.During CODEX db.App) CALLLCODEX LOG.save (x)

After reading the above, do you have any further understanding of how to import Mysql data into MongoDB? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Tags: Data code content files fields more knowledge articles types industry information information channels channels access processing support related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Huawei OPPO Reno MySQL Apple