How to import data into mongoDB
Asked Answered
G

2

12

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?

Gownsman answered 23/9, 2019 at 15:57 Comment(5)
are those username, password combination correct? do they have right permissions on verbs database? Can you run db.auth() with those credentials and cross-check?Dulcedulcea
And also hope you are not keeping the password in single quotesDulcedulcea
And if your password has special characters you have to escape them properly on the linux bash shell. This is a permissions error. Either because your user does not have the proper permissions on that database and collection or because your authentication failed.Maharani
Is my second command even valid? And yeah pretty certain they are right. And no special characters. It was in single quotes. Does that matter?Gownsman
I'm using mongoimport --host="localhost" --port="27017" --username="user" --password="password" --db="verbs" --collection="de" --file="/Users/myname/Downloads/de.json" now. This is throwing 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.. With the same credentials I can just log in using mongo -u ... -p ....Gownsman
G
31

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.

Gownsman answered 23/9, 2019 at 18:7 Comment(0)
T
1

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

Trapeziform answered 26/9, 2019 at 18:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.