Getting started with MongoDB

Michael wrote in his post about beauty of MongoDB.

I tried to run a couple lines of code and found it very easy to get started with.

There are steps to get there:

 

1. Download binaries. I  used version 1.2.3 for Win32

2. Create the data folder C:\data\db

3. Run mongod.exe

 

At this step you have MongoDB running.

 

4. Download C# driver

5. Create a console application with Visual Studio

6. Add references to driver's dlls

 

Now you are ready to write code.

 

I just copies a lines of code from Michale's post into Main method and added console output:

 

            Console.WriteLine("Create DB:");

 

            Mongo mongo = new Mongo();

 

            mongo.Connect();

 

            IMongoCollection postsTbl = mongo.getDB("BlogDB").GetCollection("Posts");

 

 

            Console.WriteLine("Insert data:");

 

            Document post = new Document();

 

            post["Tittle"] = "Tittle1";

 

            post["Timestamp"] = DateTime.Now;

 

            postsTbl.Insert(post);

 

 

            Console.WriteLine("Queries:");

 

            Document spec = new Document();

 

            spec["Tittle"] = "Tittle1";

 

            Document myPost = postsTbl.FindOne(spec);

 

 

            Console.WriteLine("Title: " + myPost["Title"]);

 

            Console.WriteLine("Timestamp: " + myPost["Timestamp"]);

 

 

            Console.ReadLine();

 

 

Finally run the programm.

 

 

 

 

 

 

Thank you for your interest!

We will contact you as soon as possible.

FOR MORE DETAILS CONTACT US

Please leave your details and we’ll get back to you as soon as possible

Oops, something went wrong
Please try again or contact us by email at info@tikalk.com
Thank you for your interest!

We will contact you as soon as possible.

Send us a message

Oops, something went wrong
Please try again or contact us by email at info@tikalk.com