Connect to remote MongoDB instance from ASP.NET

隐身守侯 提交于 2019-12-04 09:40:59

In the mongo shell, type show users. Then use the hashed password this displays for your password in the connection string.

The connection string for MongoDB is formatted as a URI, details can be found here. Below is the basic format and some examples:

mongodb://[username:password@]host1[:port1][/[database][?options]]

mongodb://127.0.0.1 

mongodb://127.0.0.1/mydatabase

mongodb://mongosrv.com:10230/mydatabase

mongodb://myadmin:secretpass@mongosrv.com:10230/mydatabase

// Or in your case it would be 

mongodb://ausername:apassword@flame.mongohq.com:27065/dunedin

You can also use MongoUrlBuilder and MongoUrl to construct or parse the connection string programatticaly. Though a bit wordy, I believe the recommended usage goes like this

var mongoUrl = new MongoUrl(settings.ConnectionString);
var mongoClient = new MongoClient(mongoUrl);
var mongoServer = mongoClient.GetServer();
var mongoDatabase = mongoServer.GetDatabase(mongoUrl.DatabaseName); 

You are obviously using mongodb-csharp. What you are using most definately is not a valid connection string. You can ask your question at the group http://groups.google.com/group/mongodb-csharp or look at the docs and code here. There is even a connection string builder so you don't need to know the exact syntax.

How does your connection string placed in Web.config look like? Exception you get indicates that it's invalid. Clarify it using MongoDB documentation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!