微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何将mongodb查询导出到csv

如何解决如何将mongodb查询导出到csv

无法使用 mongoDb 在 linux 服务器上执行以下查询

mongoexport --db MonGolog --collection dCDMonGolog --query '{$and:[{'jsonObject.responseRaw':{$regex:'<Amount>1000'}},{'jsonObject.createDate':{$gt:'2021-04-01'}},{'jsonObject.createDate':{$lte:'2021-04-08'}}]}' --csv -f jsonObject.mobile,jsonObject.createDate --out /opt/data1234.csv

低于错误

-bash: Amount: No such file or directory

甚至尝试过这种方式:

mongoexport -d MonGolog -c dCDMonGolog -q "{$and:[{'jsonObject.responseRaw':{$regex:'<Amount>1000'}},{'jsonObject.createDate':{$lte:'2021-04-08'}}]}" -f jsonObject.mobile,jsonObject.createDate --type=csv > /opt/data1234.csv

但收到此错误

 error validating settings: query '[123 58 91 123 39 106 115 111 110 79 98 106 101 99 116 46 114 101 115 112 111 110 115 101 82 97 119 39 58 123 58 39 60 65 109 111 117 110 116 62 49 48 48 48 39 125 125 44 123 39 106 115 111 110 79 98 106 101 99 116 46 99 114 101 97 116 101 68 97 116 101 39 58 123 58 39 50 48 50 49 45 48 52 45 48 49 39 125 125 44 123 39 106 115 111 110 79 98 106 101 99 116 46 99 114 101 97 116 101 68 97 116 101 39 58 123 58 39 50 48 50 49 45 48 52 45 48 56 39 125 125 93 125]' is not valid JSON: invalid character ':' looking for beginning of object key string
2021-04-16T20:01:00.729-0400    try 'mongoexport --help' for more information

似乎什么都没有运行。还有其他方法吗?

解决方法

mongoexport 查询糟透了!它需要外面的单引号和里面的双引号。 以下命令对我有用。

mongoexport -d MongoLog -c dCDMongoLog -q '{"$and":[{"jsonObject.responseRaw":{$regex:"<Amount>1000"}},{"jsonObject.createDate":{$gt:"2021-04-01"}},{"jsonObject.createDate":{$lte:"2021-04-08"}}]}' -f jsonObject.mobile,jsonObject.createDate --type=csv > /opt/data1235.csv

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。