Skip to content

Instantly share code, notes, and snippets.

@wcadap
Created January 14, 2015 04:15
Show Gist options
  • Save wcadap/6f95e91c2385b3c5bc48 to your computer and use it in GitHub Desktop.
Save wcadap/6f95e91c2385b3c5bc48 to your computer and use it in GitHub Desktop.
using MongoDB.Driver;
using System;
namespace mvcMongoDB.Models
{
public class CountryDB
{
//For Best practice, Please put this in the web.config. This is only for demo purpose.
//====================================================
public String connectionString = "mongodb://localhost";
public String DataBaseName = "CountryDB";
//====================================================
public MongoDatabase Database;
public CountryDB ()
{
var client = new MongoClient(connectionString);
var server = client.GetServer();
Database = server.GetDatabase(DataBaseName);
}
public MongoCollection<Country> Countries
{
get
{
var Countries = Database.GetCollection<Country>("Countries");
return Countries;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment