1、从MongoDB中导出csv文件;
mongoexport --host 172.16.177.214 --port 27017 --db monitor_center_backup --collection 'city' --type csv --fields _id,city_name,prov_id --out /home/ljn/mongodb_file/city.csv
2、hive中创建表结构
CREATE EXTERNAL TABLE `city`(`_id` int,`city_name` string,`prov_id` int) ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde' WITH SERDEPROPERTIES ("separatorChar"=",", "quotechar"="\"") LOCATION '/user/hive/interface_log/extend/city'
3、hive中加载csv文件
load data local inpath '/root/ljn/city.csv' into table interFace_Log.city;
4、从MongoDB迁移的数据中时间格式:2017-06-02T02:49:25.000Z,需要转换为‘yyyy-MM-dd HH:mm:ss’,语句如下:(from_unixtime(unix_timestamp(regexp_replace(server_log_2017.`time`, 'T|Z', ' ')),'yyyy-MM-dd HH:mm:ss')