Skip to content

Instantly share code, notes, and snippets.

@sht5
Created August 3, 2015 15:47
Show Gist options
  • Save sht5/71dba08455f228a1d204 to your computer and use it in GitHub Desktop.
Save sht5/71dba08455f228a1d204 to your computer and use it in GitHub Desktop.
MongoDB static class for DB
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace softwareBlogREST.Controllers
{
public static class MongoDatabase
{
public static IMongoDatabase database { get; set; }
public static IMongoDatabase GetDatabase()
{
if (database == null)
{
#if DEBUG
var client = new MongoClient("mongodb://localhost:27017");
database = client.GetDatabase("local");
#else
var client = new MongoClient("yourMongoConnectionString");
database = client.GetDatabase("yourDB");
#endif
}
return database;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment