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

type Supported Arguments Example 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()


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM