Skip to content

Instantly share code, notes, and snippets.

@JamesLouie
Created November 16, 2018 07:31
public class MongoConnector
{
private readonly IMongoClient _client;
private readonly IMongoDatabase _database;
public MongoConnector(MongoConfig config)
{
_client = new MongoClient(config.ConnectionString);
_database = _client.GetDatabase(config.DatabaseName);
}
public IMongoCollection<T> GetCollection<T>(string collectionName)
{
return _database.GetCollection<T>(collectionName);
}
}
public interface MongoConfig
{
string ConnectionString { get; set; }
string DatabaseName { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment