mongodbmongo-shellmongoexport

Mongoexport giving authentication failed error


I am trying to export MongoDB collection. MongoDB version: 3.0.15 Community

I have tried:

mongoexport --uri "mongodb://<username>:<password>@<host>:<port>/<db_name>?authsource=admin" --collection <collection_name> --out D:/mongo_export/demo.json

This is giving me authentication error as follow:

error connecting to db server: server returned error on SASL authentication step: Authentication failed.

But if I try to go in shell using:

mongo mongodb://<username>:<password>@<host>:<port>/<db_name>?authsource=admin 

I am able to go to mongo shell. This means, --uri is correct for mongoexport command.

Then why am I getting error for mongoexport?


Solution

  • As per mongo document for version 3.0, I have tried:

    mongoexport -h <host:port>-u <username>-p <password>-d <db name>-c <collection name> -o D:/mongo_export/demo.json