Created
April 15, 2013 10:56
-
-
Save baio/5387303 to your computer and use it in GitHub Desktop.
Mongo wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MongoWrapper<T> : IDisposable where T : class | |
{ | |
public MongoWrapper(string Collection) | |
{ | |
var connectionString = ConfigurationManager.AppSettings["MONGO_URI"]; | |
var hostName = Regex.Replace(connectionString, "^(.*)/(.*)$", "$1"); | |
var dbName = Regex.Replace(connectionString, "^(.*)/(.*)$", "$2"); | |
_server = MongoServer.Create(hostName); | |
_server.Connect(); | |
var db = _server.GetDatabase(dbName); | |
_collection = db.GetCollection<T>(Collection); | |
} | |
private readonly MongoServer _server; | |
private readonly MongoCollection<T> _collection; | |
public MongoCollection<T> Collection { get { return _collection; } } | |
public void Dispose() | |
{ | |
_server.Disconnect(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment