我一直在寻找一种在多个文件中将mongo导出到csv的方法。
我试过mongoExport,但没有成功。
mongoexport是一个实用程序,它生成存储在MongoDB实例中的数据的JSON或CSV导出。
发布于 2018-03-08 00:37:06
您可以在--query中使用mongoexport参数;请参阅 documentation page。
例如,我的收藏是:
> db.test.find()
{ "_id": 0, "country": "US" }
{ "_id": 1, "country": "US" }
{ "_id": 2, "country": "US" }
{ "_id": 3, "country": "AU" }
{ "_id": 4, "country": "AU" }然后我们可以运行两个mongoexport来输出每个国家:
$ mongoexport -d test -c test --type=csv --fields="_id,country" --query "{country: 'US'}"
_id,country
0,US
1,US
2,US
$ mongoexport -d test -c test --type=csv --fields="_id,country" --query "{country: 'AU'}"
_id,country
3,AU
4,AU您可能希望创建一个脚本,该脚本首先发现集合中的国家列表,然后为每个国家运行mongoexport。
https://stackoverflow.com/questions/49157661
复制相似问题