Showing posts with label non relational. Show all posts
Showing posts with label non relational. Show all posts

Thursday, November 1, 2018

Know your MongoDB

Hi All,

From past many weeks I had this eagerness to know what MongoDB is? & how it actually works. Brainstorming and learning lead to an inference that configuration is simple & easy, just follow some steps and start your journey in the new world.

So follow the trail to know what it actually is...


What is Mongo DB
A document based Database that stores Data in JSON Format. The fields can vary from document to document & YES its FREE and OPEN SOURCE.


Pros

  • Dynamic : There is no defined schema so your collection and its document can be of user's choice,  style & need.
  • No Joins required that makes it simple and easy to use
  • Flexible : Fields addition, updation is super easy and has less/no impact on he Application
  • Easy Integration & Configuration
  • It is document based & highly powerful
  • Cloud storage and distribution is key feature
  • High performance


Cons

  • Not perfectly ACID compliant
  • No stored procedure.
  • No auto-increment default option however can be achieved using Javascript code logic


Configuration

  • Download from https://www.mongodb.com/download-center
  • Alternative way to install using Homebrew as $ brew install mongodb 
  • You can configure  on local as well as remote machine
  • From 3.6 version of mongodb both mongod and mongos binaries are by default bind to LocalHost
  • Open your terminal
  • Unzip the downloaded TAR in a folder named Mongo
    • $ cd Mongo
    • $ tar-zxvf mongodb-osx-ssl-x86_64-4.0.3.tgz
  • Move
    • $ sudo mv mongodb-osx-ssl-x86_64-4.0.3 /usr/local/mongodb
  • Create a folder where Mongodb can store/write data, by default location is /data/db which needs to be created manually with proper permissions
    • $ sudo mkdir -p /data/db
    • $ sudo chown [LOGGED_IN_USER] /data/db
    • The default location can also be changed using 
      • $ mongod --dbpath /your_directory
  • To access mongodb commands you have to create a ~/.bash_profile file & assign /usr/local/mongodb/bin to $PATH environment variable
    • $ cd ~
    • $ pwd /users/[LOGGED_IN_USER]
    • $ touch .bash_profile
    • $ open .bash_profile 
      • Above command opens a text editor, paste below 2 commands in there and save
      • export MONGO_PATH=/usr/local/mongodb
      • export PATH=$PATH:$MONGO_PATH/bin
  • Restart the terminal 
  • $ mongo -version
  • $ mongod 
    • above command start the mongo daemon
  • Open another terminal window
    • $ mongo
  • Now in this terminal window you will see 
      MongoDB server version: 4.0.3
      Welcome to the MongoDB shell



What is Mongo

  • This is a JS shell interface for MongoDB which access the database


What is MongoD

  • This is a daemon, a host process for the database which runs mongodb process in background.
  • This has several default params associated with it
    • It runs on port 27017
    • Stores data in /data/db

What is bash profile & its usage in MongoDB
  • Its a hidden file that loads before the Terminal loads the shell environment
  • It contains shell configurations and preferences.
  • MongoDB paths are set in this file


Difference between SQL and Mongodb


Sql ServerMongoDB
DatabaseDatabase
TableCollection
IndexIndex
RowDocument
ColumnField
JoinsLink
PartitionRange Partition