mongoexport读取带有空格的字段 [英] mongoexport reading a field with a space

查看:212
本文介绍了mongoexport读取带有空格的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将MongoDB中的联系人"集合导出到CSV文件中.我正在使用MongoExport.我的文档如下所示:

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"
    }
]
}

我正在使用的命令是: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 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"

我遇到的问题是获取地址信息"字段.我尝试用{}包装地址信息",并添加了下划线,例如address_info,但是它不起作用.我不断收到错误消息:位置位置过多...".有任何建议吗?

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?

此外,我如何强制该命令覆盖磁盘上已经存在的csv文件?

Also, how can i force the command to overwrite the csv file it exists on disk already?

推荐答案

我也遇到了同样的问题.通过使用双引号将字段包装起来解决了该问题. 例如,使用双引号如下所示,在Windows mongo 3.2.3中可以使用地址信息".

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.

这篇关于mongoexport读取带有空格的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆