Alvin
Alvin

Reputation: 8499

Mongodb connection string Invalid keyword data source

I am using C# official MongoDB nugget library.

I hosted the web service on Windows Azure, and the MongoDB database at Mongolab.

I connected to a server with the code below:

connection = mongodb://user:[email protected]:45077"
_server = MongoServer.Create(connection);

Previously it is working fine and it work fine at local testing server, but at my latest publish I get error below:

ExceptionMessage":"Invalid keyword 'data source'."," ....... at MongoDB.Driver.MongoConnectionStringBuilder.set_Item(String keyword, Object value)

Anyone know what is the problem?

Upvotes: 0

Views: 2002

Answers (1)

Rebecca
Rebecca

Reputation: 14402

The following works for me:

var client = new MongoClient("mongodb://user:[email protected]:45077");
var server = client.GetServer();
var database = server.GetDatabase("MyDataBaseName");

If your username or password contains special characters, you might want to encode them.

Please also note that your database username and password may well be different to your MongoLab login!

Upvotes: 1

Related Questions