Terminologies:Â
A MongoDB Database can be called the container for all the collections.Â
- A collection is a bunch of MongoDB documents. It is similar to tables in RDBMS.
- A document is made of fields. It is similar to a tuple in RDBMS, but it has a dynamic schema here. Documents of the same collection need not have the same set of fields
Getting StartedÂ
After you install MongoDB, you can see all the installed files inside C:\ProgramFiles\MongoDB\ (default location). In the C:\Program Files\MongoDB\Server\3.2\bin directory, there are a bunch of executables, and a short description about them would be:Â
mongo: The Command Line Interface to interact with the db.
mongod: This is the database. Sets up the server.
mongodump: It dumps out the Binary of the Database(BSON)
mongoexport: Exports the document to Json, CSV format
mongoimport: To import some data into the DB.
mongorestore: to restore anything that youâve exported.
mongostat: Statistics of databases
Now, you can start running the MongoDB Server. Fire up a Command Prompt and go to the location where MongoDB executables are installed (C:\Program Files\MongoDB\Server\3.2\bin\ but this path might change in the future). Just type âmongodâ and it will pop an error saying the path \data\db doesnât exist:Â

This means that the default path of storage C:\data\db was not found. So you can make a directory C:\data\db on your own or with the mkdir command. You can also change the default path by the switch âdbpath <path> with the âmongodâ command.
After making this directory, run the âmongodâ command again and it will start the server on the port 27017. Â

Now, we need to start our client. So, open up another terminal and change the directory to the MongoDB path. Just type âmongoâ and your client would be up, trying to connect to the server. Â

This would be the CLI to interact and administer the databases. This shell is kind-of a JS console. You can try in different JS commands to check that out. Since our client is up, we can now start working on the database. We can see that the database in use is named as âtestâ. You can see the databases using  âsee dbsâ and switch to other databases like âlocalâ by typing âuse <dbname>â.Â
Note that there are no existing collections. This can be seen by typing the command âshow collectionsâ.Â
Letâs start by adding some data into our database. We can create a collection by the method db.createCollection(name, { size : ..., capped : ..., max : ... } )Â
But we have created a randomly generated json file( of employee data) and we would import it onto our database by typing Â
mongoimport --jsonArray --db test --collection employee_data <
C:\mongoJson\employee_data.json
This would import the Employee data json document referred by the path given in the collection named âemployee_dataâ of database âtestâ.Â

Now to ensure the collection is imported you can type âshow collectionsâ in the shell. You can use methods like count(), find(), findOne() to do some very basic queries with your document.Â
You can see that in every document there is a field called â_idâ which was not provided in the data imported. The reason is that MongoDB provides a default â_idâ (if not provided explicitly) which is a 12 byte hexadecimal number which assures the uniqueness of every document. You can even change this â_idâ field but this is not recommended.Â

Indexing: You can also use indexing if your query returns more than one document. For example, db.employee_data.find() returns all the documents in the collection but if you just want the 7th one then, just do db.employee_data.find()[6] and it will return the specific document. [Note : Indexing starts from 0 here].Â
Projections: Letâs say for a query you want only some specific details and not the whole set of detail in the document. You can use projections for this. After your query object just make the needed fields as 1 and others would be assumed as 0 automatically. But remember that the â_idâ field is always assumed to be 1 implicitly and if you donât want to see the ugly looking â_idâ field, then you need to say this in your projection by â_id : 0âÂ
Queries:Â
1. Find the number of employees with company âGEEKS FOR GEEKSâÂ
> db.employee_data.find( { company= âGEEKS FOR GEEKSâ } ).count()2. Show the detail of all the employees named âSandeep Jainâ Â
> db.employee_data.find( { name: âSandeep Jainâ }Here, all the documents which matches with the given name would show up.Â
3. Show the age, gender and email, but not â_idâ of the employee named âHarshit Guptaâ. (Assume that there is only one employee named Harshit Gupta). Usage of ProjectionsÂ
> db.employee_data.find( { name: âHarshit Guptaâ }, { _id:0, age:1, gender:1, email:1 } )We can also store the output of queries into variables and then make interesting queries with them too.Â
4. Print the name of all the female employees. Â
> var femaleEmp = db.employee_data.find( { gender: âfemaleâ } )
for ( var i = 0 ; i < femaleEmp.count() ; i++){
print ( femaleEmp[i].name)
}
> db.employee_data.find( { gender: "female" }, { _id:0, name:1 } )
Note that the 1st solution just prints out the names while 2nd one prints it in Object Format.Â
Conclusion
In summary, MongoDB is a flexible, document-based database system that stores data in collections of JSON-like documents. After installing MongoDB, you use the mongod command to start the server and mongo to open the client shell. Data can be imported easily using mongoimport, and documents automatically get a unique _id if not specified. Basic commands like find(), count(), and createCollection() help you manage and query your data. You can also use projections to fetch specific fields and indexing to access specific documents quickly. Overall, MongoDB is beginner-friendly and powerful for handling dynamic, structured data without the rigid rules of traditional databases.