MongoDB mongoimport 时间格式处理

1、问题

在公司数据分析同事开发过程中,会用上fo循环上亿次,导致总运行时间很长,其中有取mongodb的collectio中的时间字段,

此时间字段为字符串类型,虽然可以使用,但是将类型换为date(ISODate),程序运行时间大大降低。

2、mongoimport 导入数据库,字段变为date方法如下

要到时间格式,要对原csv中的格式进行转换

原来为:

2020-03-01 12:00:00,'One'

现在变为:

2020-03-01 12:00:00,'One'

导入脚本改为:

mongoimport --port=27120 --db idap_zl --collection test --type csv --columnsHayeType --file testimsi.csv --fields timeneed.date(2020-03-01 00:00:00),name.string()

--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 .

typeSupported ArgumentsExample Header Field
auto() None. misc.auto()
binary(<arg>)
  • base32 (RFC4648 encoding schema)
  • base64 (RFC4648 encoding schema)
  • hex
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()
原文地址:https://www.cnblogs.com/xibuhaohao/p/12470323.html