I have been playing around a bit with MongoDB for the first time of my life. It's really a very nice experience and have a lot of the "just works"-feeling that I have started to get used to from frameworks like NancyFx and Simple.Data.
But when i pushed it to AppHarbor I ran into problems. That all had with me not reading stuff properly…
I have been playing around a bit with MongoDB for the first time of my life. It's really a very nice experience and have a lot of the "just works"-feeling that I have started to get used to from frameworks like NancyFx and Simple.Data.
But when i pushed it to AppHarbor I ran into problems. That all had with me not reading stuff properly…
AppHarbor has a nice feature that replaces stuff in your .config files on deploy. That could be used for setting Production-environment values to your environment configuration. For example changing the connection string for a database.
The add-on for Mongo DB at AppHarbor has a nice article describing this in detail. But I read it quickly and put the connection string in the
It should be added as an
key="MONGOHQ_URL" value="mongodb://localhost/DotVoter"/>
You can then read that value as simple as this:
private readonly MongoCollectionpublic MongoRepository()_collection;
{
var connectionString =
ConfigurationManager.AppSettings.Get("MONGOHQ_URL");
var client = new MongoClient(connectionString);
var server = client.GetServer();
var con = new MongoUrlBuilder(connectionString);
var db = server.GetDatabase(con.DatabaseName);
_collection = db.GetCollection
}
With that in place … it just works!
If you liked this post ... here's more for you:
Published by
on Last updated