【问题标题】:MongoDB export to CSV the results of an aggregate unwind query? [duplicate]MongoDB 将聚合展开查询的结果导出到 CSV? [复制]
【发布时间】:2018-01-23 04:46:31
【问题描述】:

在尝试将我的查询输出到 CSV 时,我收到“验证设置错误:查询无效 JSON:json:无法将字符串解组为 map[string]interface {} 类型的 Go 值”。

我的查询是: 'dev_experts:{$aggregate([{$unwind:"$expertise"}])}'

我如何“解组”它?我已经通过 Robomongo 运行了查询,我可以看到我想要导出的结果,但我无法通过那里导出它们。

提前致谢。

【问题讨论】:

  • 看起来很像这个问题:stackoverflow.com/questions/36435512/…
  • 嗨皮埃尔。是的,这是同一类型的问题,但我不知道如何将这种情况应用于此类查询。有小费吗? :)
  • 所以你想在 Go 中获取输出并将结果写入 csv?

标签: json mongodb csv robo3t database


【解决方案1】:

也许你应该试试这个查询语法,虽然我不是 Robomongo 专家;)

db.dev_experts.aggregate([{$unwind:"$expertise"}]);

cf https://docs.mongodb.com/manual/reference/operator/aggregation/unwind/ 了解更多信息。

【讨论】:

  • 这在 Robomongo 中可以正常查询,因为我可以查看它的结果,但我希望将结果导出到 CSV。
  • 在终端中使用 mongoexport,输入:mongoexport --username x --password x --host x --db mydb --collection dev_experts --query '{dev_experts:{$aggregate([{$unwind:"$expertise"}])}' --type=csv --fields id,expertise --out "./myfile.csv"
  • 仍然报告它无法将字符串解组为 map[string]interface {} 的 Go 值类型
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多