Skip to content

Instantly share code, notes, and snippets.

@leetschau
Last active May 28, 2016 12:14
Show Gist options
  • Save leetschau/1eca199593f7bef4441d42b71c17a678 to your computer and use it in GitHub Desktop.
Save leetschau/1eca199593f7bef4441d42b71c17a678 to your computer and use it in GitHub Desktop.
MongoDB导出的json数据中,时间字段前面都有{$date: 2016.04.04},$date不能被Elasticsearch识别,需要去掉,从{"timeStart: {$date: "xxx"}}变成{"timeStart: "xxx"}
#!/bin/bash
sed 's/{\"\$date\":\(\".\{10\}T.\{12\}Z\"\)}/\1/g' f1000.json > temp.json
sed -i 25d temp.json
mongoimport -d test -c strDate --type json --file temp.json
# sample data:
"timeStart":{"$date":"1015-09-01T00:00:00.000Z"},"timeEnd":{"$date":"2018-03-02T00:00:00.000Z"},
"timeStart":{"$date":"2016-09-01T00:00:00.000Z"},"timeEnd":{"$date":"2021-04-0kT00:00:00.000Z"},
"timeStart":{"$date":"2017-09-01T00:00:00.000Z"},"timeEnd":{"$date":"2021-05-09T00:00:00.000Z"},
"timeStart":{"$date":"2017-09-01T00:00:00.000Z"},
"timeStart":"$date":"2017-09-01T00:00:00.000Z"},
"timeStart":{$date:1017-09-01T00:00:00.000Z},
timeStart:{$date:2017-09-01T00:00:00.000Z},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment