Mongo Db Part 01

Mongo Db Part 01

Introduction

  1. It is a document-oriented database

  2. Provides high performance, high availability, and easy scalability

  3. It works on the collection and document

Sql Vs Nosql database

  1. In sql database the data model is structured

  2. In Nosql database the data model can be of the following 4 types

    1. Graph Based Database

    2. Document Based Database

    3. Key-Values database

    4. Column family database

  3. The data structure is predefined in sql database

  4. The data structure is dynamic in the NoSql database

  5. SQL database is vertically scalable

  6. NoSQL databases are horizontally scalable

  7. Query Language for SQL database is: MySQL, SQL

  8. A query language for a NoSQL database is dependent on the NoSQL database used

  9. Define property for SQL database is acid

  10. The define propoerty for Nosql data is BASE/CAP

NoSQL Databases

  1. HBASE

  2. Cassandra

  3. MongoDB

Structure Of A MongoDB database

  1. First, we need to create a database that will act like a physical container

  2. The collection group of the document is a collection more like the table schema in sql database

  3. Document is the actual value of collection

Establishing a Connection with MongoDB

import pymongo

# Provide the mongodb localhost url to connect python to mongodb.
client = pymongo.MongoClient("mongodb://localhost:27017/neurolabDB")

# Database Name
dataBase = client["neurolabDB"]

# Collection  Name
collection = dataBase['Products']

# Sample data
d = {'companyName': 'iNeuron',
     'product': 'Affordable AI',
     'courseOffered': 'Machine Learning with Deployment'}

# Insert above records in the collection
rec = collection.insert_one(d)

# Lets Verify all the record at once present in the record with all the fields
all_record = collection.find()

# Printing all records present in the collection
for idx, record in enumerate(all_record):
     print(f"{idx}: {record}")