1
votes

I have been created Mongodb Database via add-on of MongoLab on Azure Cloud. I have been able to connect to database but i always get below exception;

Command 'count' failed: db assertion failure (response: { "assertion" : "unauthorized db:YourDefinition ns:YourDefinition.Terms lock type:1 client:94.245.107.14", "assertionCode" : 10057, "errmsg" : "db assertion failure", "ok" : 0.0 })

How can i get rid of this problem ?

Update :

Here is my connection string

"mongodb://YourDefinitionDB:hQIkxfNlgF8rp6o6zb4KDVe_t8RILePrBLPieIvWS1M-@ds045087.mongolab.com:45087/YourDefinitionDB"

I have used wrong database name but still i get below exception.

Command 'authenticate' failed: auth fails (response: { "errmsg" : "auth fails", "ok" : 0.0 })

I can say that it works on external gui but not via .net driver.

3
The error message indicates that you're trying to connect to a database called "YourDefinition". Is that what your database is called?robert
@robert I have updated question.Freshblood
Your connection string appears to be missing a database at the end. Also, you should probably edit out the password.robert
@robert I have also tried it via database parameter. Now i have updated connection string in the question. But still i get invalid credentials for YourDefinitionDB database :((Freshblood
Everything worked when i created new database with different name.Freshblood

3 Answers

3
votes

This guide may help you get up and running: https://www.windowsazure.com/en-us/develop/net/tutorials/website-with-mongodb-mongolab/

Specifically these code snippets:

private string connectionString = System.Environment.GetEnvironmentVariable("CUSTOMCONNSTR_MONGOLAB_URI");
private string dbName = "myMongoApp";

and

MongoServer server = MongoServer.Create(connectionString);
MongoDatabase database = server[dbName];

You would just need to set the "CUSTOMCONNSTR_MONGOLAB_URI" environment variable to be your MongoLab URI. Eg:

mongodb://<dbuser>:<dbpassword>@<host_name>.mongolab.com:<port>/<db_name>

EDIT: Just noticed your update containing the connection string. Looks like you're missing the db portion at the end of it. See the example connection string above.

0
votes

You need to provide credentials for the database when you initialize the connection. Either login to mongolab or find them via azure (not sure how they set that up) and provide them before attempting operations on the database.

0
votes

"mongodb://YourDefinitionDB:hQIkxfNlgF8rp6o6zb4KDVe_t8RILePrBLPieIvWS1M-@ds045087.mongolab.com:45087/YourDefinitionDB"

Your connection string, assuming it's reflecting how your real connection string looks, is showing the database name twice. The format should be:

mongodb://username:[email protected]:port/database