MongoDB


Database is place to store data but never thought we would have so many flavors. Though I'm no expert in DB, just to see so many ways to store and retrieve data is so fascinating.
NoSQL has been around for many years now. MongoDB is NOSQL database. Its document based database not relational.

Terms in MongoDB
Database is database i.e. we can have many db. We will see more about this later.
Collection is like a table.
Document is like a row.
All document will have "_id" generated which is unique within a collection

Some shell commands -
Show db -  This command will list all database
use db     -  This command will place us in the mentioned database
Show collections - This command will list all collections in database

Assume we need to create customer database. Just type use customerdb
then we can create collections(tables) like customers,orders.
E.g.
           x   = { "name" : "ABC",
                      "age"    : 30,
                      "sex"    : "Male",
                      "addr" : "101 baahubali street",
                      "city"  : "Chennai" }

now customer collection can be added to customerdb database -
db.customer.insert(x)

 CRUD -
db.collection.insert()
db.collection.remove()
db.collection.update()
db.collection.find()

Popular posts from this blog

PF2XLS - Python

Stock Analysis - Example with Ashok Leyland

Python on IBM i