Getting an error trying to import a dataset . the last lab in chapter 1

The error is below . looks like the user m103-application-user is not authorized to insert into products .

bash-4.4# mongoimport --port 27000 -u “m103-application-user” -p "m103-applicati>
2020-10-16T22:28:42.281+0000 no collection specified
2020-10-16T22:28:42.281+0000 using filename ‘products’ as collection
2020-10-16T22:28:42.305+0000 connected to: mongodb://localhost:27000/
2020-10-16T22:28:42.339+0000 Failed: (Unauthorized) not authorized on test to execute command { insert: “products”, ordered: false, writeConcern: { w: “majority” }, $db: “test” }
2020-10-16T22:28:42.339+0000 0 document(s) imported successfully. 0 document(s) failed to import.

Hello and welcome,

From this one

(Unauthorized) not authorized on test to execute command { insert: “products”, ordered: false, writeConcern: { w: “majority” }, $db: “test” }

Seems it is trying to run it on $db:"test"

So probably the --db applicationData is missed ?

If not, please include the full connection string.


edit hoping it will help a bit further, a small break down of mongoimport is included below:

  • imports csv or json files
  • useful options
    • --db=<dbname> selects a database
    • --collection=<collectionName> selects a collection inside <dbname>
    • --file=<file> what are we importing (normally file.json).
    • --drop useful when we are replacing an existing collection.

If --collection isnt there, it creates one using the file basename. So file.json would produce dbname.file. If --dbname isn’t there you’ll see test.file namespace.

3 Likes

Appreciate it , that was it . Thanks