I was trying to learn basics of using Mongo database recently. I am capturing some of the things I learnt below so it will be helpful for other people.
Installing Mongo database on Linux:
First lets intall Mongo db. I use a Ubuntu OS laptop. Below are steps to follow to install Mongo -
- In Linux, it is better to use the package manager to install software. In Ubuntu, we can use the apt commands to install mongo
- To ensure authenticity of the package that needs to be installed, Ubuntu requires packages be signed with GPG keys. As a first step, let us download the key from ubuntu.com.
- Next we will need to add the repository for mongo in the list of sources for your ubuntu laptop. I will do that by creating a list file for mongo -
- Next keep the ubuntu package database updated
- now lets install mongo. Install the latest version always unless you have a specific reason to use an older version
- Now this installs mongodb in your Ubuntu. To start Mongo services, in a terminal window, type - mongod . This will start mongo services with port 27017
- To log into mongo shell and query the database, in another terminal type - mongo
- show dbs
- use <db name>
- show collections
- db.<collection>.find()
- db.<collection>.insert({"test":"123"})
There are many more commands to learn - db.<collection>.update, etc
At least hopefully this will get you started. Enjoy!
At least hopefully this will get you started. Enjoy!
Comments
Post a Comment