Marcel Braasch
Marcel Braasch

Reputation: 1183

How to import data into mongoDB

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?

Upvotes: 13

Views: 14125

Answers (2)

Santosh
Santosh

Reputation: 11

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

Upvotes: 1

Marcel Braasch
Marcel Braasch

Reputation: 1183

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.

Upvotes: 32

Related Questions