1.mongodbimport命令使用
1.1基本使用
该情况需要在csv中加上列名称 问题是没有指定数据类型默认都是字符串
mongoimport.exe --host 127.0.0.1:50000 -d xueba -c test1 --file D:\Develop\MongoDB\TXB_20201117_13000.csv --type json --headerline
关键参数说明:
h,–host :代表远程连接的数据库地址,默认连接本地Mongo数据库;
–port:代表远程连接的数据库的端口,默认连接的远程端口27017;
-u,–username:代表连接远程数据库的账号,如果设置数据库的认证,需要指定用户账号;
-p,–password:代表连接数据库的账号对应的密码;
-d,–db:代表连接的数据库;
-c,–collection:代表连接数据库中的集合;
-f, --fields:代表导入集合中的字段;
–type:代表导入的文件类型,包括csv和json,tsv文件,默认json格式;
–file:导入的文件名称
–headerline:导入csv文件时,指明第一行是列名,不需要导入;
1.2指定csv列数据类型
相关参数
–fields=<field1[,field2]>, -f=<field1[,field2]>
Specify a comma separated list of field names when importing csv or tsv files that do not have field names in the first (i.e. header) line of the file.
To also specify the field type as w