2

I'm exporting documents of collection called team in MongoDB as csv file. For example I have this MongoDB document:

{
    "_id" : "149",
    "official_name" : "yaChAaoiqn",
    "common_name" : "VMlEXjTOZE",
    "country" : "YSpbYyPWSo",
    "championship" : "rwSbupqsln",
    "uniform" : [ 
        "first_colour", 
        "second_colour", 
        "third_colour"
    ]
}

I use the following command to export documents in csv:

Z:\Program Files\MongoDB\Server\3.0\bin>mongoexport --db paul --collection team
--type=csv --fields _id,official_name,common_name,country,championship,"uniform[0]","uniform[1]","uniform[2]" --out "C:\path\to\outputFile\output.csv"

This is the csv I have in output:

_id,official_name,common_name,country,championship,uniform[0],uniform[1],uniform[2]
149,yaChAaoiqn,VMlEXjTOZE,YSpbYyPWSo,rwSbupqsln,"","",""

The csv file tells me there are some problems with uniform.
How must I set the uniform field in the command to export from MongoDB rightly an array?

1

1 Answer 1

2

I dont think this is currently possible. I think your best bet is to use the uniform field without referring to the element index. All values from the array will then be written to the csv file, and you could correctly reformat them post-export.

mongoexport --db paul --collection team --type=csv --fields _id,official_name,common_name,country,championship,uniform --out "C:\path\to\outputFile\output.csv"
Sign up to request clarification or add additional context in comments.

1 Comment

Ok, I wrote a java program to change that portion of csv file. Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.