首页  :: 新随笔  :: 管理

mongodb 导出制定的查询结果

Posted on 2019-07-14 14:10  季枫  阅读(6558)  评论(0)    收藏  举报

 

1、mongo查询语句:

db.quarkContext.find({"submitTime":{"$gt":ISODate("2019-07-13T00:00:00.000+08:00")},"rawResult":{$regex:/\"ok\":0/}},{"info.sId":1,"submitTime":1,"responseTime":1})

2、编写导出查询语句文件quary.js

db.quarkContext.find({"submitTime":{"$gt":ISODate("2019-07-13T00:00:00.000+08:00")},"rawResult":{$regex:/\"ok\":0/}},{"info.sId":1,"submitTime":1,"responseTime":1}).forEach(
    function(document) {
        print(document.info.sId + "," + document.submitTime + "," + document.responseTime);
    }
)

3、执行语句

 ./mongo 127.0.0.1:40000/shtel /data/service/mongodb/bin/query.js > /data/service/mongodb/bin/result.csv
query.js:查询条件及输入指令
result.csv:输出结果文件
智读 | 成都会领科技有限公司官网 | 智读App下载 | 每天听本书的博客 | |