Quantcast
Viewing latest article 1
Browse Latest Browse All 17

kettle小试,抽取MongoDB数据至Mysql

Image may be NSFW.
Clik here to view.

1.MongoDB Input :填写连接信息,添加查询条件,如:

{$query:{‘hp_stat_date’:’2015-09-28′}}

2.由于在Mongo中我的日期定义是Date类型,ISODate(“2015-08-25T00:00:00Z”),在MongoDB Input 的输出值中,是这样表示的,{‘$date’:’2015-08-25T00:00:00Z’},所以需要对字符串作一些处理。

3.处理date,用了js脚本作正则替换,不清楚是否有更好的方法

var new_json=“”

var replacement = “\””+/\d+-\d+-\d+T\d+:\d+:\d+\.\d+\w+/g.exec(json)+“\””

new_json = json.replace(/\{\s*\“\$date\”\s*:\s*\”\d+-\d+-\d+T\d+:\d+:\d+\.\d+\w+\”\}/g,replacement)

Image may be NSFW.
Clik here to view.

4.Json Input :从上一步字符串结果中读取json,转换为响应字段

需要注意:填写从字段中获取源new_json,字段中时间类型的format为

yyyy-MM-dd’T’HH:mm:ss.SSSZ

直接 MongoInput  ->  插入/更新 就成。。。

Image may be NSFW.
Clik here to view.

在Mongo Input 会遇到个问题,就是mongo中 ISODate 的比较查询,正确的姿势应该如下:

{$query:{‘date’:{‘$gt’:{$date:’2015-09-26T00:00:00Z’},’$lt’:{$date:’2015-09-29T00:00:00Z’}}}}


Viewing latest article 1
Browse Latest Browse All 17

Trending Articles