Thursday 27 February 2020

Mongodb for beginners (Starting to end)

MongoDB is a rich document-oriented NoSQL database

In order to work with MongoDB, first we need to install MongoDB in our computer. To do this, visit the official download center and download the version for your specific OS. (Here i am talking about windows)

next is installation process. Once done, head over to the place where you installed MongoDB. Go to (C: -> Program Files -> MongoDB -> Server -> 4.0(version) -> bin)

In the bin directory, you’ll find an interesting couple of executable files.

mongod
mongo
Let’s talk about these two files.

mongod stands for “Mongo Daemon”. mongod is a background process used by MongoDB. The main purpose of mongod is to manage all the MongoDB server tasks. For instance, accepting requests, responding to client, and memory management.

mongo is a command line shell that can interact with the client (for example, system administrators and developers).

Now let’s see how we can get this server up and running. To do that on Windows, first we need to create a couple of directories in your C drive. Open up your command prompt inside your C drive and do the following:

C:\> mkdir data/db
C:\> cd data
C:\> mkdir db

The purpose of these directories is MongoDB requires a folder to store all data. MongoDB’s default data directory path is /data/db on the drive. Therefore, it is necessary that we provide those directories like so.

If you start the MongoDB server without those directories, you’ll get error

We can always work by going to the mongodb bin folder and we can execute the necessary mongodb commands from there. But to save time
we can set up your environment variables by doing Advanced System Settings -> Environment Variables -> Path(Under System Variables)

Simply copy the path of our bin folder and hit OK! In my case it’s C:\Program Files\MongoDB\Server\4.0\bin-> Edit

Working with MongoDB

There’s a bunch of GUIs to work with MongoDB server such as MongoDB Compass, Studio 3T and so on.

They provide a graphical interface so you can easily work with your database and perform queries instead of using a shell and typing queries manually.

But in this article we’ll be using command prompt to do our work so that we can become master of mongodb memory.

Now it’s time for us to dive into MongoDB commands that’ll help you to use with your future projects.

1. Open up your command prompt and type mongod to start the MongoDB server.
2. Open up another shell and type mongo to connect to MongoDB database server.

In MongoDB, the first basic step is to have a database and collection in place. The database is used to store all of the collections, and the collection in turn is used to store all of the documents. The documents in turn will contain the relevant Field Name and Field values.


The "use" command is used to create a database in MongoDB. If the database does not exist a new one will be created.MongoDB will automatically switch to the database once created.

No comments:

Post a Comment

Baisic Useful Git Commands

  Pushing a fresh repository Create a fresh repository(Any cloud repository). Open terminal (for mac ) and command (windows) and type the be...