What is NoSQL?1NoSQL= "Not Only SQL“Designed for:Big DataReal-time web appsFlexible data modelsEmphasizes scalability, performance, andflexibility
2.
2Why NoSQL?Limitations oftraditional SQL:Fixed schemasPoor horizontal scalingAdvantages of NoSQL:Schema-less modelsHigh performanceEasy replication and partitioning
3.
Types of NoSQL•Key-value• Graph database• Document-oriented• Column family3
4.
Use Cases forNoSQL Social networks IoT applications Real-time analytics Product catalogs Content Management Systems (CMS)
5.
How does NoSQLvary from RDBMS?10SQL NoSQLRelational Database Management System (RDBMS) Non-relational or distributed database system.These databases have fixed or static or predefined schema They have dynamic schemaThese databases are best suited for complex queries These databases are not so good for complex queriesVertically Scalable Horizontally scalableFollows ACID property Follows BASE property NoSQL (often interpreted as Not only SQL) database It provides a mechanism for storage and retrieval of data that is modeledin means other than the tabular relations used in relational databases.
11Create Database Afterconnecting to your database using mongosh, you can see whichdatabase you are using by typing db in your terminal. Show all databases To see all available databases, in your terminal type show dbs Change or Create a Database You can change or create a new database by typing use then the name of thedatabase.
12.
12Create Collection Method1 You can create a collection using the createCollection() database method. Method 2 You can also create a collection during the insert process.
13.
13Insert Documents Thereare 2 methods to insert documents into a MongoDB database. insertOne(): To insert a single document, use the insertOne() method. insertMany(): To insert multiple documents at once, use the insertMany()method.
14.
14Find Find Data:There are 2 methods to find and select data from a MongoDBcollection, find() and findOne(). To select data from a collection in MongoDB, we can use the find() method. This method accepts a query object. If left empty, all documents will be returned. To select only one document, we can use the findOne() method. This method accepts a query object. If left empty, it will return the first documentit finds.
16Projection Both findmethods accept a second parameter called projection. This parameteris an object that describes which fields to include in the results.
17.
17Projection We usea 1 to include a field and 0 to exclude a field. Notice that the _id field is also included. This field is always included unlessspecifically excluded.
18.
18Projection Let's excludethe date category field. All other fields will be included in the results. We will get an error if we try to specify both 0 and 1 in the same object.
19.
19Update Document Toupdate an existing document we can use the updateOne() or updateMany()methods. The first parameter is a query object to define which document or documentsshould be updated. The second parameter is an object defining the updated data. The updateOne() method will update the first document that is found matchingthe provided query.
20.
20Update DocumentInsert ifnot found: If you would like to insert the document if it is not found,you can use the upsert option.
22Delete Documents deleteOne():The deleteOne() method will delete the first document that matchesthe query provided. deleteMany(): The deleteMany() method will delete all documents that match thequery provided.
23.
23MongoDB Query OperatorsNameDescription$eq Matches value that are equal to a specified value$gt, $gte Matches values that are greater than (or equal to a specifiedvalue$lt, $lte Matches values less than or ( equal to ) a specified value$ne Matches values that are not equal to a specified value$in Matches any of the values specified in an array$nin Matches none of the values specified in an array$or Joins query clauses with a logical OR returns all$and Join query clauses with a loginal AND$not Inverts the effect of a query expression$nor Join query clauses with a logical NOR$exists Matches documents that have a specified field$regex Allows the use of regular expressions when evaluating field values$text Performs a text search$where Uses a JavaScript expression to match documents
25Update Operators Fields:The following operators can be used to update fields: $currentDate: Sets the field value to the current date $inc: Increments the field value $rename: Renames the field $set: Sets the value of a field $unset: Removes the field from the document Array: The following operators assist with updating arrays. $addToSet: Adds distinct elements to an array $pop: Removes the first or last element of an array $pull: Removes all elements from an array that match the query $push: Adds an element to an array
27ExampleIncrement likes by1:Rename body to content:Set a new field status to "published":Remove the category field:
28.
28ExampleAdd a tagonly if it’s not already present:Remove last element of the tags array:Remove first element:Remove "news" from the tags array:Add "announcement" to the tags array:
Editor's Notes
#3 Key-Value StoresDefinition: Store data as a collection of key-value pairs. Highly performant and simple.Examples:Redis: In-memory store, often used for caching, real-time analytics, and messaging.Riak: Distributed and fault-tolerant, designed for high availability.Graph DatabasesDefinition: Designed for data with complex relationships. Data is stored as nodes and edges.Examples:Neo4j: Popular graph database, ideal for social networks, recommendation engines.HyperGraphDB: A generalized graph database with support for hypergraphs. Document-Oriented DatabasesDefinition: Store semi-structured data as documents, typically in JSON or BSON format.Examples:MongoDB: Widely used, flexible schema, good for content management, IoT, etc.CouchDB: Focuses on ease of use and multi-master replication.Column Family StoresDefinition: Store data in columns rather than rows, suitable for large-scale distributed systems.Examples:Cassandra: High scalability, fault-tolerant, used by Facebook, Netflix.HBase: Built on Hadoop, good for big data analytics. SummaryEach NoSQL type is optimized for specific use cases:Key-value: Fast lookupsGraph: Relationship-heavy dataDocument: Flexible schemasColumn family: Massive datasets with complex queries