Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB - can't get data exported with mongoexport due to auth failed

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.

like image 391
L.D Avatar asked Mar 11 '15 18:03

L.D


People also ask

What is the difference between Mongodump and Mongoexport?

mongoexport is a command-line tool that produces a JSON or CSV export of data stored in a MongoDB instance. mongodump is a utility for creating a binary export of the contents of a database.

How do I export data from MongoDB to CSV?

Export MongoDB to CSV (e.g. Excel) Open the Export Wizard and select your export source. This screen only appears if you haven't chosen an item in the Connection Tree, run a previous query, or selected specific documents. Next, choose CSV as the export format then click Next.

Where is Mongoexport located?

MongoDB provides a utility called mongoexport to its users, through which users can export data from MongoDB databases to a JSON file format or a CSV file format. This utility is to be found in the MongoDB's bin subfolder (the path can be read like this: /mongodb/bin).


2 Answers

Worked perfect with that additional parameter --authenticationDatabase admin.

like image 166
L.D Avatar answered Oct 13 '22 00:10

L.D


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
like image 41
jsky Avatar answered Oct 13 '22 00:10

jsky