NoSQL

A brief look at MongoDB

In this article, we are going to look at a NoSQL Database named MongoDB. MongoDB is a document oriented database that targets high performance and high volume. In this article, I am going to install a MongoD server on windows 10 64bits and use the C# client, but other operating systems for the server, as well as other languages for the client are avalaible.

From server installation to DataBase creation (Windows 10 64bits)

The first thing that we need is to download and install the .msi of the community version of MongoDB for Windows 64-bit. (I have personally downloaded the version 3.4.3).

Then we create a folder where the database will be installed in the disk. I have chosen to create a folder MongoDB in “C:\Data\”. But it could be anywhere else.

Third we need to start the server using mongod.exe :

> "C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe" --dbpath "C:\Data\MongoDB"

We can now connect to the server using  mongo.exe (on a new command window),

> "C:\Program Files\MongoDB\Server\3.4\bin\mongo.exe"

… and create a new database named testdb.

> use testdb

We have now a new database ready to be used!

Using the DataBase with C# client

Installing C# client via Nuget

The C# client can be downloaded from Nuget by installing the MongoDB.Driver package. I have personally installed it along a Console Application in .Net 4.6.2.

Creating documents

Remember that in NoSQL, we do not need define the structure of a collection before inserting the data. Here I am going to create two documents in the collection “persons“.

Finding a document

And now we are going to find one of them to see if the insertion went well. For that we are going to use a filter on the profile_id of a person.

Which works fine!

{ "_id" : ObjectId("58dfc1e6a515863c90cc3976"), "profile" : { "profile_id" : "1", "surname" : "Khakurel", "firstname" : "Pradip" } }

MongoDB is very intuitive and easy to use!!!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s