using MongoDB.Driver; var client = new MongoClient("mongodb://localhost:27017"); var database = client.GetDatabase("mydb");
var collection = database.GetCollectionIn this example, we get a reference to the "mycollection" collection using the GetCollection method and then insert a BsonDocument into it using the InsertOne method. Package library: The C# driver for MongoDB is available as a NuGet package named MongoDB.Driver.("mycollection"); var document = new BsonDocument { {"name", "John"}, {"age", 30}, {"job", "developer"} }; collection.InsertOne(document);