问题
I am trying to export a collection of 'contacts' from MongoDB into a CSV file. I am using MongoExport. My document looks as follows:
{
"id": 1,
"name": [
{
"FirstName": "joe",
"LastName": "doe"
}
]
"address info": [
{
"city": "London",
"postcode": "N1 1AA"
}
]
}
The command I am using is: mongoexport --username x --password x --host x --db mydb --collection mycol --type=csv --fields name.FirstName,name.LastName,Address Info.city,Address Info.postcode --out "c:\myfile.csv"
The issue I am having is getting the fields for "address info". I tried wrapping "address info" with {} and also adding an underscore like address_info but it didn't work. I keep getting the error: "too many positional arugments...". Any sugesstions?
Also, how can i force the command to overwrite the csv file it exists on disk already?
回答1:
I had the same problem too. Solved it by Wrapping the field using double quotes. Ex Using double quotes as follows " Address Info " in windows mongo 3.2.3 works.
来源:https://stackoverflow.com/questions/36344949/mongoexport-reading-a-field-with-a-space