• Published Date — 28 December 2017


How to get Started with MongoDb on Windows

What is MongoDB?

MongoDB is a free open source, cross-platform database. Classified as a NoSQL database. It's a document oriented database program, in which each database contains collections and collections contain documents. Each document can be different in terms of the number of fields and size of the content. MongoDB replaces the old table structure relational database by JSON-like documents with dynamic schemas, it makes the integration of data in various types of applications faster and easier.

In this post, we are going to setup MongoDB on our Windows machine and then start with some basic queries. First, you have to download MongoDB from the official website

Once the download has finished double click on installer

And Click Next

After selecting the check box click next

Choose the complete installation

The setup is now ready to install MongoDB on your machine, click install Once the installation is completed the installation window must be closed if not close it. Now it's time to setup the PATH environment variable for MongoDB. To do this press windows key and search System then hit enter, now select Advanced System Settings from the left pane. A mini System properties windows is now popped,

Click on Environment Variables , Now from the Environment Variables window select the Path under System variable section and click edit

Now a tiny window is popped, simply click New and paste this line C:\Program Files\MongoDB\Server\3.4\bin

NOTE: Depending on the version of your MongoDB, mine is 3.4 change it with yours if it different from my mine.

And click ok, now close all pop-ups and restart your PC.

Verify MongoDB installation

To verify MongoDB installation open command prompt or any other terminal and type mongod , now MongoDB shell must be running and waiting for the connections.

To initiate a new instance of connection to MongoDB shell, open a new command prompt window and type mongo.

Congrats you have just initiated a new connection to MongoDB shell.

Now you can run MongoDB queries on this window or connect your application with it.

NOTE: The mongod cmd window must not be closed in order to work with MongoDB or the new mongo cmd window.

HERE IS THE SOME BASIC QUERIES OF MongoDB TO GET YOU STARTED

− How to show all databases

show dbs

− How to use a database

use databaseName

− How to show all collections from a database

show collections (only when switched to a database)

− How to insert a new data into an existing collection or made a new collection?

db.myCollection.insert({name:"Zubeen", subject:"Database"})

− How to show/retrieve all data from the collections?

db.myCollection.find();

− How to find a particular entry from a collection?

db.myCollection.find({name:"Zubeen"})

− How to update a instance/document in a collection?

db.myCollection.update({name:Zubeen},{$set:{subject:programming}})

− How to remove an entry?

db.myCollection.remove({name:"Zubeen"}) /// It will remove all the persons that matches the name Zubeen

− How to remove a single entry which has duplicates?

db.myCollection.remove({name:"Zubeen"}).limit(1)




If you want to learn more check out the official documentation


If you like this post, don't forget to share :-)






About the Author

I once had a problem in my life then I decided to choose java now I have problem factory


Zub

New Posts



Top 6 Coding IDEs

No Comments 4 November 2017


Why Node.js is awesome!

No Comments 4 November 2017


Top 10 Best Extensions for Chrome

No Comments 29 December 2017