mongoexport reading a field with a space

风格不统一 提交于 2019-12-12 05:01:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!