[英]MongoDb/MongoVue Export part of a composite key
I wanted to use MongoVue to create a quick export of all the ids for portion of a given collection. 我想使用MongoVue为给定集合的一部分创建所有ID的快速导出。
I have a document that has an _id field which is a composite key. 我有一个文档,该文档的_id字段是复合键。
For example. 例如。
{
"_id" : {
"GroupID" : 3,
"ThingyID" : 320486
},
"HowManyOwned" : 42,
"IsAwesome" : true
}
I want to create an export of all the ThingyIDs for Group 3. 我想为组3创建所有ThingyID的导出。
Of course if I make my query something like this. 当然,如果我这样查询。
db.GroupThingy.find({ "_id.GroupID" : 3 }, { "_id.ThingyID" : 1 })
I'll get back all the composite keys. 我将取回所有组合键。 I wanted to use MongoVue to just quickly create this export. 我想使用MongoVue快速创建此导出。 If I use that query I get back an export of. 如果我使用该查询,则会返回导出。
Document[2 Keys]
Document[2 Keys]
Document[2 Keys]
What I was hoping to get was 我希望得到的是
either 要么
3,12345
3,3838
3,3777
3,1111
Or even better would be just 甚至更好的只是
12345
3838
3777
1111
I could write a program for this but there has to be a quick way to accomplish this that I just don't know about. 我可以为此编写程序,但是必须有一种我不知道的快速方法来完成。
Aggregation Framework doesn't help me get a csv export... but something like this will only support 20k documents 聚合框架无法帮助我导出csv ...但是类似这样的东西仅支持20k文档
db.GroupThingy.group(
{
key: {
"_id.ThingyID": 1,
"_id.GroupID":1
},
cond: { "_id.GroupID": 3 },
reduce: function(curr, result){
result.ThingyID2 = curr._id.ThingyID
},
initial: { "ThingyID2": 0 }
});
Well I finally found out how to get the export using mongoexport thanks to this question: how to export collection to csv in mongodb 好了,由于这个问题,我终于找到了如何使用mongoexport导出的方法: 如何在mongodb中将集合导出到csv
However I kept getting the error: 但是我一直得到错误:
ERROR: too many positional options... and this post helped me find the answer: What does "too many positional options" mean when doing a mongoexport? 错误:位置选项过多...这篇文章帮助我找到了答案: 执行mongoexport时,“位置选项太多”是什么意思?
So my final solution to run the mongoexport was: 因此,我运行mongoexport的最终解决方案是:
mongoexport
--host myHostName
--db theDB
--collection GroupThingy
--fields "_id.ThingyID"
--csv
--query "{'_id.GroupID':3}"
(options on there own lines for readability) (为了方便阅读,各行都有选项)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.