CS340 · Annotated SlidesChapter 10 — NoSQL and Object-Oriented Databases
Chapter 10 · Annotated slides

NoSQL and Object-Oriented Databases

Relational vs. non-relational databases, NoSQL families, MongoDB documents and collections, JSON and BSON, CRUD operations in MongoDB, Compass and Atlas, and object-oriented DBMSs compared with RDBMSs.

Slide text Study notes Highlight: key words Tips, tricks & traps Seen again elsewhere How it can come up

NoSQL and Object-Oriented Databases

CS340 · Chapter 10
1

LEARNING GOALS

CLO1: Demonstrate the knowledge in designing, updating, and querying basic NoSQL-Database Systems. (Knowledge & Understanding) Chapter objectives:

 Define the key concepts behind NoSQL database systems.

 Define the key concepts behind Object Oriented database

systems.

 Compare relational and non-relational database concepts.

 Create a MongoDB database and perform basic operations.

2
Exam weight Low

    TOPICS

    1. Introduction of a NoSQL Database (MongoDB) including, installation, MongoDB Compass and Atlas
    2. MongoDB Elements: Database, Collections and Documents
    3. Perform basic NO SQL CRUD operations on Documents a. Creating documents b. Updating documents c. Deleting documents d. Querying documents
    4. MongoDB Compass
    5. Introduction of Object Oriented Databases.
    3
    Exam weight Low

      RELATIONAL DATABASES

       The purpose of relational databases is the storage and

      retrieval of highly structured data used mainly in an organization.

       Relational model has persisted (with changes) since the

      1970s.

       A relational database typically stores structured data in

      tables (relations) containing specific data and types of data.

       Relational databases use Structured Query Language

      (SQL).

      4
      Exam weight Low
        ★ Past exam
        Slide 5: NON-RELATIONAL DATABASES
        Exam weight High
        1. NoSQL ("not only SQL"): flexible or no schema, horizontal scaling, high availability, often relaxed consistency.
        🎯 How this can come up · 1 question
        MCQ

        Horizontal scaling (scaling out) means:

        Slide 6: NON-RELATIONAL
        Exam weight Low
          Slide 7: NOSQL EXAMPLES
          Exam weight High
          1. Families: document (MongoDB), key–value (Redis), column-family (Cassandra), graph (Neo4j).
          🎯 How this can come up · 1 question
          MCQ

          MongoDB is a:

          Slide 8: NON-RELATIONAL DATABASES (NOSQL)- MONGODB
          Exam weight Low

            MONGODB DOCUMENT EXAMPLE

            {

            "_id" : "888665555", "Fname" : "James", "Minit" : "E", "LName" : "Borg", "dBirth" : "10-Nov-2007", "Address" : "450 Stone Houston TX", "Sex" : "M", "Salary" : 55000, "Dnumber" : "5", "Dependents" : [

            {

            "DepName" : "Ann",

            "DepSec" : "F", "Relation" : "Daughter"

            }

            ]

            composite

            }

            9
            Exam weight Low
              Slide 10: NON-RELATIONAL DATABASES (NOSQL)- MONGODB
              Exam weight Low
                Slide 11: NON-RELATIONAL DATABASES (NOSQL)- MONGODB
                Exam weight Low

                  QUICK COMPARISON OF ELEMENTS

                  RDBMS

                  MongoDB

                  Database

                  Database

                  Table

                  Collection

                  Tuple/Row

                  Document

                  column

                  Field

                  Table Join

                  Embedded Documents

                  Primary Key

                  Primary Key (Default key _id provided by MongoDB itself)

                  Database Server and Client

                  12
                  Exam weight High
                  1. MongoDB ↔ relational: database ↔ database, collection ↔ table, document ↔ row, field ↔ column, embedding/linking ↔ joins.
                  🎯 How this can come up · 1 question
                  MCQ

                  In MongoDB, a collection corresponds to a relational:

                  Slide 13: MongoDB Relational DB
                  Exam weight Low
                    Slide 14: MONGODB FEATURES
                    Exam weight Low
                      Slide 15: JSON IN MONGODB
                      Exam weight Low
                      1. Documents are JSON-like (stored as BSON): objects { } and arrays [ ].
                      Slide 16: JSON OBJECT AND ARRAY
                      Exam weight Low
                        Slide 17: JSON DATA TYPES
                        Exam weight Low
                          Slide 18: JSON USED IN MONGODB
                          Exam weight Low
                            Slide 19: JSON USED IN MONGODB
                            Exam weight Low
                              Slide 20: DISADVANTAGE OF JSON
                              Exam weight Low
                                Slide 21: DISADVANTAGE OF JSON
                                Exam weight Low
                                  Slide 22: Slide 22
                                  Exam weight Low
                                    Slide 23: DATA TYPES USED IN MONGODB
                                    Exam weight Low

                                      CRUD Operations in MongDB

                                      Create Update Read Delete

                                      24
                                      Exam weight High
                                      1. CRUD: insertOne/insertMany, find, updateOne/updateMany ($set), deleteOne/deleteMany.
                                      🎯 How this can come up · 1 question
                                      MCQ

                                      Which MongoDB call changes a field in matching documents?

                                      Slide 25: CREATE OPERATIONS
                                      Exam weight Low
                                        Slide 26: READ OPERATIONS
                                        Exam weight Low
                                          Slide 27: UPDATE OPERATIONS
                                          Exam weight Low

                                            UPDATE OPERATIONS

                                            With replaceOne you can only replace the entire document, while updateOne allows for updating fields.

                                            Since replaceOne replaces the entire document - fields in the old document not contained in the new will be lost.

                                            With updateOne new fields can be added without losing the fields in the old document.

                                            28
                                            Exam weight Low
                                              Slide 29: DELETE OPERATIONS
                                              Exam weight Low

                                                MONGODB COMPASS AND ATLAS

                                                The GUI for MongoDB.

                                                Compass is an interactive tool for querying, optimizing, and analyzing your MongoDB data in a visual environment.

                                                Compass is free to use and source available, and can be run on macOS, Windows, and Linux.

                                                Download Compass We will get to know MongoDB Atlas in a lab this Tuesday and Wednesday in sha’ Allah, stay tuned.

                                                30
                                                Exam weight Low
                                                  Slide 32: OODBMS HISTORY
                                                  Exam weight Low
                                                    Slide 33: RDBMS VS OODBMS: EXAMPLE
                                                    Exam weight Low
                                                    1. RDBMS: tables, SQL, simple types. OODBMS: objects with methods, OIDs, no impedance mismatch with OO code.
                                                    Slide 34: RDBMS VS OODBMS (2)
                                                    Exam weight Low