mongoimport choosing field type

后端 未结 4 1119
臣服心动
臣服心动 2020-12-17 18:21

When importing data from file (csv in my case) mongoimport automatically choose data type for each field.

Is it possible to choose data type manually for specific fi

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-17 18:48

    When importing CSV/TSV to mongodb, the option --columnsHaveTypes can help to define the columnstypes. But the document seems very unclear. I tried several times until finally did succeed. You should add option --columnsHaveTypes and change every column after --fields and remember using "\" before "(" and ")". for example, change:

    mongoimport -h foohost -d bardb -c fooc --type tsv --fields col1,col2,col3 --file path/to/file.txt
    

    into

    mongoimport -h foohost -d bardb -c fooc --type tsv --fields col1.int32\(\),col2.double\(\),col3.string\(\) --columnsHaveTypes --file path/to/file.txt
    

提交回复
热议问题