mongo版本: mongodb-enterprise-4.2.2
操作系统:win7-64
从mysql中导出json文件,使用mongoimport导入到mongo时报错:
mongoimport.exe -u root -p admin -d btc_new -c btc_node --upsert --file btc_node.json
报错如下:
2020-08-21T14:11:29.798+0800 error connecting to host: could not connect to server: connection() : auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-1": (AuthenticationFailed) Authentication failed.
从这里找到答案,需要增加一个option:authenticationDatabase,最终执行如下:
mongoimport.exe -u root -p admin --authenticationDatabase admin -d btc_new -c btc_node --upsert --file ../btc_node.json
导入后查看mongo发现只有一条document,应该是json文件的问题,再行修改。
--从mysql导出csv文件,然后再倒入mongo中,采坑如下:
1)、使用HeidiSQL,导出的csv文件,编码为utf-8,使用命令:
mongoimport.exe -u root -p admin --authenticationDatabase admin -d btc_new -c btc_node --fields=filter,ip --type csv --file ../btc_node.csv
不明白已经使用了--fields选项,仍然将表头导入了mongo中,只能使用以下命令将表头删除:
db.getCollection('btc_node').remove({ 'filter' : 'filter' });