Python Database Interation
Python Database Interation
Asst. professor
IICMR - MCA
Introduction to NoSQL database
SQL Vs NoSQL
Key-value Databases
Wide-column stores
Graph Databases
JSON Object
Every data element in the database is stored as a key value pair consisting of an
attribute name (or "key") and a value.
Use cases include shopping carts, user preferences, and user profiles
While a relational database stores data in rows and reads data row by row, a
column store is organized as a set of columns. This means that when you want to
run analytics on a small number of columns, you can read those columns directly
without consuming memory with the unwanted data
Store data in nodes and edges. Nodes typically store information about
people, places, and things, while edges store information about the
relationships between the nodes.
In order to retrieve all of the information about a user and their hobbies,
a single document can be retrieved from the database. No joins are
required, resulting in faster queries.
Developed in the
Developed in the late 2000s with a focus on
Development 1970s with a focus on
scaling and allowing for rapid application change
History reducing data
driven by agile and DevOps practices.
duplication
Vertical (scale-up
Scaling Horizontal (scale-out across commodity servers)
with a larger server)
NoSQL databases can be larger than SQL databases – data models in NoSQL
databases are typically optimized for queries and not for reducing data
duplication,. Storage is currently so cheap that most consider this a minor
drawback, and some NoSQL databases also support compression to reduce the
storage footprint.
Depending on the NoSQL database type you select, you may not be able to
achieve all of your use cases in a single database.
Depending on the NoSQL database type you select, you may not be able to achieve
all of your use cases in a single database. For example, graph databases are
excellent for analyzing relationships in your data but may not provide what you
need for everyday retrieval of the data such as range queries. When selecting a
NoSQL database, consider what your use cases will be and if a general purpose
database like MongoDB would be a better option.
• insert ( ) • updateOne ( )
• deleteOne ( )
• insertOne ( ) • find( ) • updateMany ( )
• deleteMany ( )
• insertMany ( ) • replaceOne ( )
CRUD SQL
Create INSERT
Read SELECT
Update UPDATE
Delete DELETE
Python Programming By Sanjay Mate, IICMR-MCA
44
Create Collection in database
• insert ( )
Insert a Single Document
• insertOne ( )
• insertMany ( )
• insert ( )
Insert Multiple Documents¶ • insertOne ( )
db.collection.insertMany( • insertMany ( )
[ <document 1> , <document 2>, ... ],
{
writeConcern: <document>,
ordered: <boolean>
}
)
db.emp.insertMany
(
[ {empno:104, ename:”Vilas”, sal : 50000, job: “Manager” , dept:10 } ,
• Load From
Java Script File
db.emp.insertOne(
{empno:101, ename:"Sanjay", sal : 50000, job: "Manager" , dept:10 } )
db.emp.insertOne(
{empno:102, ename:"Rajesh", sal : 20000, job: "Analyst" , dept:20 } )
db.emp.insertOne(
{empno:103, ename:"Priti", sal : 30000, job: "Analyst" , dept:10 } )
> load(“emp.js”)
https://pypi.org/project/pymongo/