--columnsHaveTypes
¶
New in version 3.4.
Instructs mongoimport that the field list specified in --fields
, --fieldFile
, or --headerline
specifies the types of each field.
Field names must be in the form of <colName>.<type>(<arg>)
. You must backslash-escape the following characters if you wish to include them in an argument: (
, )
, and .
type | Supported Arguments | Example Header Field |
---|---|---|
auto() |
None. | misc.auto() |
binary(<arg>) |
user thumbnail.binary(base64) |
|
boolean() |
None. | verified.boolean() |
date(<arg>) |
Alias for date_go(<arg>) . Go Language time.Parse format. |
created.date(2006-01-02 15:04:05) |
date_go(<arg>) |
Go Language time.Parse format | created.date_go(2006-01-02 15:04:05) |
date_ms(<arg>) |
Microsoft SQL Server FORMAT format | created.date_ms(yyyy-MM-dd H:mm:ss) |
date_oracle(<arg>) |
Oracle Database TO_DATE format. | created.date_oracle(YYYY-MM-DD HH24:MI:SS) |
decimal() |
None | price.decimal() |
double() |
None. | revenue.double() |
int32() |
None. | followerCount.int32() |
int64() |
None. | bigNumber.int64() |
string() |
None. | zipcode.string() |
mongoimport:指定字段的类型,防止将数字型的字符串导入成数值类型
1、正常模式导入
mongoimport -d idpad_zl -c trs_action_dzwl_zm --type csv --columnsHaveTypes --fields "_id.string(),netbar_wacode.string(),start_time.string(),imsi.string(),imsi_text.string(),imei.string(),device_longitude.string(),device_latitude.string(),tmsi.string(),rssi.string(),band.string(),plmn.string(),tel_number.string(),site_address.string(),device_name.string(),vendor_name.string(),province.string(),city.string()" --file ./test.csv
示例:
如果不加,就要加上转换:--columnsHaveTypes --fields
2、嵌套模式导入
1)原始数据
{495616020064,201912071925,张府园地铁站1号口},PZRW,460020616594750,000000000000000,121.312,31.212,1560351577,147,9,46005,1353145,碰撞01,森根科技,福建省,漳州市
2)导入语句
mongoimport -d idpad_zl -c trs_action_dzwl_zm_test --type csv --columnsHaveTypes --fields "_id.imsi.string(),_id.start_time.string(),_id.site_address.string(),xnetbar_wacode.string(),imsi_text.string(),imei.string(),device_longitude.string(),device_latitude.string(),tmsi.string(),rssi.string(),band.string(),plmn.string(),tel_number.string(),device_name.string(),vendor_name.string(),province.string(),city.string()" --file ./test.csv