How to import data into mongoDB

点点圈 提交于 2020-05-15 10:17:06

问题


I'm trying to import a large data file in JSON format . I'm using

mongoimport --db verbs --collection de --file "/Users/marcelbraasch/Downloads/de.json"

to import the data. This is going through, however, I'm getting the following exception:

Failed: (Unauthorized) not authorized on verbs to execute command { insert: "de", ordered: false, writeConcern: { w: "majority" }, $db: "verbs" }

I already tried combinations like this

mongoimport -h localhost:27017 -u 'user' -p 'password' --db verbs --collection de --file "/Users/myname/Downloads/de.json"

but none of it worked. My mongo instance is running in a docker container, if this information matters. What do I need to do?


回答1:


Found the answer here. This missing keyword was authenticationDatabase. The command that worked for me was:

mongoimport --db verbs --collection de --authenticationDatabase admin --username user --password password --drop --file /Users/myname/Downloads/de.json.




回答2:


I was struggling with the same issue, adding keyword --authenticationDatabase worked for me.



来源:https://stackoverflow.com/questions/58066115/how-to-import-data-into-mongodb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!