command 'authenticate' failed: auth failed (response: { "ok" : 0.0, "errmsg" : "auth failed", "code" : 18, "codeName" : "AuthenticationFailed" }) Description: An

4,775 views
Skip to first unread message

Hariom Sharma

unread,
Sep 12, 2017, 3:10:30 AM9/12/17
to mongodb-user

command 'authenticate' failed: auth failed (response: { "ok" : 0.0, "errmsg" : "auth failed", "code" : 18, "codeName" : "AuthenticationFailed" })

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: MongoDB.Driver.MongoCommandException: Command 'authenticate' failed: auth failed (response: { "ok" : 0.0, "errmsg" : "auth failed", "code" : 18, "codeName" : "AuthenticationFailed" })

Source Error: 

Line 29:         //var oc = new BsonDocument("sasa", "saa");
Line 30: 
Line 31:         foreach (var item in _documents.FindAll())
Line 32:         {
Line 33:             Response.Write(item.ToString());

Source File: d:\Yogendra\MyPractise\WebSite3\11-09-17.aspx.cs    Line: 31 

Stack Trace: 


Code_ --

protected void Page_Load(object sender, EventArgs e)
    {
        MongoUrl url = new MongoUrl(ConfigurationManager.ConnectionStrings["mycon"].ConnectionString);
        var client = new MongoClient(url);
        //var db = client.GetDatabase(url.DatabaseName, null);
        // now you can get collections from db

       // var connectionString = "mongodb://admin:password@localhost/admin";
        MongoClient Client_ = new MongoClient(url);
        MongoServer ms = Client_.GetServer();
        ms.Ping();

        MongoDatabase md = ms.GetDatabase("AshaSoft");
        MongoCollection<BsonDocument> _documents = md.GetCollection<BsonDocument>("AshaFileType");
        //var oc = new BsonDocument("sasa", "saa");

        foreach (var item in _documents.FindAll())
        {
            Response.Write(item.ToString());
        }
    }

Wan Bachtiar

unread,
Sep 18, 2017, 10:03:09 PM9/18/17
to mongodb-user

Hi,

It seems that you’ve been having auth problem with your MongoDB. I would recommend to see MongoDB Enable Auth. You can also follow the steps listed on the page to setup and enable access control.

In regards to your snippet code, please see MongoDB C#: Make a Connection to see how to create a connection.
Note that you’re creating MongoClient object twice in your code example.

Regards,
Wan.

Reply all
Reply to author
Forward
0 new messages