15

I have a Mongo DB database and I trying to export couple "records" from one of the collections present in this database. Here is the command I am trying to use and the error I am getting:

mongoexport --collection my_collection --out my_collection.json --limit 10 --db my_db --username mongoadmin --password secret --host localhost

connected to: localhost
assertion: 18 { ok: 0.0, errmsg: "auth failed", code: 18 }

Don't know what is wrong here.

L.D
  • 1,279
  • 3
  • 15
  • 31
  • 1
    Try to use mongo admin command first. – Mihai8 Mar 11 '15 at 18:51
  • 3
    just a guess, try: `--authenticationDatabase admin`, assuming user credentials (mongoadmin) are stored in `admin` database – Ori Dar Mar 11 '15 at 18:51
  • To use mongo admin see http://stackoverflow.com/questions/23721866/mongodb-2-6-1-command-line-authentication-fails – Mihai8 Mar 11 '15 at 18:54
  • It worked perfectly. I got a JSON file having 10 "records". To the command line I used I only added the parameter you suggested and everything worked perfectly. Many thanks. – L.D Mar 11 '15 at 18:57

4 Answers4

25

Worked perfect with that additional parameter --authenticationDatabase admin.

Vince Bowdren
  • 8,326
  • 3
  • 31
  • 56
L.D
  • 1,279
  • 3
  • 15
  • 31
  • Yup. Worked Smooth. Thanks – shadab.tughlaq Jan 10 '17 at 11:51
  • I have been trying to export data for like an hour, I can connect with mongosh but couldn't do anything with mongodump and mongoexport... Why that basic argument solved the problem? Why I can't just simply export data like I can connect to the database... – Guven Degirmenci Nov 26 '20 at 13:05
14

Adding the additional parameter didn't work for me.

I contacted mLab support and was told the shell and/or driver I was connecting with was not compatible with MongoDB 3.0.x, the version that my database was running.

I installed 3.0.10 and was then able to connect successfully.

Carla Drago
  • 141
  • 1
  • 3
1

For some reason no matter what i did, mongoexport or mongodump utilities didnt work for me as the default user, even after resetting my password, whilst I was, however, able to connect as default user to the mongo shell.

But the solution for me was from the settings page of your database on mlabs.com you can create more users, and i was then able to connect to these utilities with the new user. You can probably create new users in the shell too, but id just use the online tool.

mongoexport -h <serverURL:port> -d <database> -c <collection> -u <newuser> -p <newpassword> -o collection.json
jsky
  • 2,225
  • 5
  • 38
  • 54
1

Adding a new user/password in mlabs.com settings worked for me.