Mongo Authentication Exception - OmIndia

Teach To India

Tuesday, September 12, 2017

Mongo Authentication Exception

MongoDB.Driver.MongoAuthenticationException,MongoDB.Driver.MongoAuthenticationException -


ommand '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());



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("DatabaseName");
        MongoCollection<BsonDocument> _documents = md.GetCollection<BsonDocument>("CollectionName");
        //var oc = new BsonDocument("sasa", "saa");

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

No comments:

Post a Comment

Comments

Popular