MongoDB Hello world!

2018 – Working with MongoDB in .NET

2016 – Working with MongoDB in .NET

1-Download MongoDB – or Choose the ZIP package, download & extract the files to c:\mongodb. Files aligned as :

Server mongod.exe
Router mongos.exe
Client mongo.exe
MonitoringTools mongostat.exe, mongotop.exe
ImportExportTools mongodump.exe, mongorestore.exe, mongoexport.exe, mongoimport.exe
MiscellaneousTools bsondump.exe, mongofiles.exe, mongooplog.exe, mongoperf.exe

Make a new folder c:\mongodb\dbase. Start the server with :

//ref -
mongod.exe --dbpath C:\mongodb\dbase

2-Download .NET driver or (v2.7.3 is the last version supports framework v4.5.2)
3-Download Robomongo v1.3.1 or

ref –

27017 The default port for mongod and mongos instances. You can change this port with port or –port.
27018 The default port for mongod when running with –shardsvrcommand-line option or the shardsvr value for the clusterRole setting in a configuration file.
27019 The default port for mongod when running with –configsvrcommand-line option or the configsvr value for the clusterRole setting in a configuration file.

4-Add the MongoDB Driver DLLs as reference to your project and paste the following :

//FYI - MongoClient object is thread safe, so you can put it in a static field – 
IMongoDatabase db;

private void button1_Click(object sender, EventArgs e)
		var connectionString = "mongodb://localhost:27017";

		MongoClient client = new MongoClient(connectionString);
		db = client.GetDatabase("SignatureErrors");
	catch (Exception x)

private void button2_Click(object sender, EventArgs e)
	var document = new BsonDocument();
	document.Add("name", "Steven Johnson");
	document.Add("age", 23);
	document.Add("subjects", new BsonArray() { "English", "Mathematics", "Physics" });

	IMongoCollection<BsonDocument> collection = db.GetCollection<BsonDocument>("SignatureErrorsRECS");

By: |10/05/2019|categories: /