You are on page 1of 7

Python Programming 2

Mohamad Sadra Salman Noori


Database
• All variables and objects are in RAM!
• Limited and volatile
• File system is not good enough
• Not complex enough for structured data and complex queries
• What is DB?
• Organized collection of data
• What does it do?
• Store, update, delete, retrieve and manage data efficiently
• Why DB?
• DBMS offers a variety of techniques to store & retrieve data and etc
• DBMS?
• Software engine providing API for users
Database Design
• Database
• Collection of entities
• Amir school database ID Name Role grade Class
• Entity 0012345679 salman noori Teacher [12] -

• Distinguishable object 0012345678 Sadra Student 10 1


• Teacher, staff, student, … salman

• Entity -> table, collection 0098765432 Mohamad


noori
Student 11 2

• Attribute 0056473829 Salman noori Student 12 2

• Specific property of an entity 0098765431 Sadra noori Teacher [10,11] -


• Id, name, salary, role, grade, …
• Columns of your tables, collections

ID Name Grade Class ID Name grade


0012345678 Sadra salman 11 1 0012345679 salman noori [12]

0098765432 Mohamad noori 10 2 0098765431 Sadra noori [10,11]

0056473829 Salman noori 12 2


MongoDB
• Relational DB
• Table-based database
• Highly structured data stock information, geolocation and …
• Use SQL(Standard Query Language)
• NoSQL
• Document-based, Graph-based, …
• Complex and unstructured data such as texts, social media and …
• MongoDB
• Document-based NoSQL DB
• Super Easy and widely used
• Use MQL(Mongo Query Language)
• Database has multiple collections
• Collections has multiple documents
• Each document has its own data schema, properties and values
MongoDB
• Download and install “MongoDB” Engine
• https://fastdl.mongodb.org/windows/mongodb-windows-x86_64-4.4.4-signed.msi
• Add MongoDB bin folder to system environment path

• Check MongoDB is installed properly


• cmd -> mongo --version

• Download and install “Robo3T” GUI


• https://robomongo.org/download
• Download Robo3T only

• Check Robo3T is installed properly


• Launch Robo3T

• Download and install "PyMongo“ Driver


• pip install pymongo
• import pymongo inside a python script and just run it
Work with Robo3T
• Create Connection

• Create Database

• Create Collection

• Insert/Find/Update/Delete

• BSON/JSON
Python MongoDB
• Create Connection

• Create Database

• Create Collection

• Insert/Find/Update/Delete

• Advance query

You might also like