NoSQL with MongoDB
What is NoSQL?
Non-tabular databases aka ‘not only SQL’ (NoSQL) databases use to store data differently than relational tables. The main type of data models are: document, key-value, wide-column, and graph.
Types and usage of NoSQL data models
Document Databases: ecommerce platforms, trading platforms, mobile app development
Key-Value Stores: shopping carts, user preferences, user profiles
Column-Oriented Databases: analytics
Graph Databases : fraud detection, social networks, knowledge graphs
What is MongoDB?
Mongo DB is a Document database used to build highly available and scalable internet applications.
Mongo DB is popular with developers who use agile methodologies. Because its flexible schema approach.
lets see some of MongoDB Operations.
assumptions: database collection name students
Insert Operations
db.students.insertOne({{
“name”: “Smith”,
“dateOfBirth”: “1990–01–15T00:00:00Z”,
“subjects”: [“Application frameworks”, “Computer architecture”],
“isActive”: true
}})
to insert a record you can use insertOne operation with the document
Find Operation
db.students.find({name:’Jhon’})
db.students.find({_id: ObjectId(“62405b3bc7bf03b7aefbe4e4”)})
using find operation you can find records according to entered key and value.
Update Operation
db.students.updateOne({_id:ObjectId(“624081d5c7bf03b7aefbe4e6”)},{$set:{isActive:false}})
updateOne operation gets a unique field as a first parameter. Then you can pass the required part to be updated with the $set keyword.
How to add a new element in to an array?
So, in order to do that you can use $push keyword. This example shows, how to add an element to an existing array called “subjects”
db.students.updateOne({_id:ObjectId(“62405b3bc7bf03b7aefbe4e4”)},
{$push:{subjects:”Distributed Computing”}})
Delete Operation
db.students.deleteOne({_id:ObjectId(“624081d5c7bf03b7aefbe4e6”)})