mongodb-csharp How to connect MongoDb Database from application


Example

Define parameters

private static IMongoClient _client;
private static IMongoDatabase _database;
private static IMongoCollection< -collection class name- > _collection;

Assign values to parameters

_client = new MongoClient("mongodb://localhost:27017");
_database = _client.GetDatabase("database name here");
_collection = _database.GetCollection< -collection class name- >("collection name here");