mongodb 数据导入导出
mongoexport 命令异常方便简单强大!
连接数据库:
jkmiao@jkmiao-ipin:~$ mongo 192.168.1.xx:xxx/jd_58tc_raw
1. 导出10条数据到标准输出
mongoexport -h 192.168.1.xx:xxxxx -d jd_58tc_raw -c jd_raw_38 -f 'jdJob' -q '{"jdJob.age":/25岁/}' --limit 10
2. 到文件
$ mongoexport -h 192.168.1.97:27027 -d jd_58tc_raw -c jd_raw_38 -f 'jdJob' -q '{"jdJob.age":/25岁/}' --limit 10 --pretty -o jd_58tc_output.json 2016-01-31T16:30:58.612+0800 connected to: 192.168.1.97:27027 2016-01-31T16:30:58.716+0800 exported 10 records
3. 导入
mongoimport -h localhost:27017 -d jd_raw -c jd_58tc_raw --drop ./jd_58tc_output.json
完整使用:
jkmiao@jkmiao-ipin:~$ mongoexport -h 192.168.1.97:27027 -d jd_58tc_raw -c jd_raw_38 -f 'jdJob' -q '{"jdJob.age":/岁/}' --limit 1000 -o jd_58tc_output.json 2016-01-31T16:40:47.815+0800 connected to: 192.168.1.97:27027 2016-01-31T16:40:47.921+0800 exported 1000 records
jkmiao@jkmiao-ipin:~$ mongoimport -h localhost:27017 -d jd_raw -c jd_58tc_raw --drop ./jd_58tc_output.json 2016-01-31T16:41:44.405+0800 connected to: localhost:27017 2016-01-31T16:41:44.406+0800 dropping: jd_raw.jd_58tc_raw 2016-01-31T16:41:44.513+0800 imported 1000 documents
每天一小步,人生一大步!Good luck~