4-3 - Mongo DB and Node Js
4-3 - Mongo DB and Node Js
js with MongoDB
Introduction,
MongoDB Create Database,
Create Collection, Insert, delete,
update, join, Sort, Query.
MongoDB
• MongoDB is a document database storing data
in a JSON format called BSON.
• It is open-source, cross-platform, and designed
for application development and scaling.
• The name 'MongoDB' is derived from
'Humongous' meaning enormous.
-built to store a huge amount of data and also perform fast
Now you are ready to work with the Mongo Shell to interact with the database.
Step 5: Basic Commands in Mongo Shell
5(b). insertMany()
db.<collection>.insertMany() inserts multiple
documents into a collection. It cannot insert a single document.
KIET> db.department.insertMany([
... { "_did": 101, "department_name": "Computer Science" },
... { "_did": 102, "department_name": "Mathematics" }
... { "_did": 103, "department_name": "ECE" }
6) Query Data
db.<collection_name>.find(): Retrieves all documents from
the specified collection. Example:> db.personal.find()
7) Update Data
• MongoDB provides the following methods to
update existing documents in a collection:
- db.collection.updateOne() - Modifies a single
document in a collection.
- db.collection.updateMany() - Modifies one or more
documents in a collection.
7(a) Example: updateOne()
student> db.personal.updateOne
({SName:’Abhi’}, {$set:{SAge:19}})
7(b) Example: updateMany()
8) Delete Data:
To Delete Documents in a Collection
2 methods to delete one or more documents in a collection.
MongoDB Node.js
Feature MongoDB Server Driver
Connects
Purpose Operates the database applications to the
database
Client-side library for
Platform Server-side software Node.js
Requires MongoDB
Dependency Works independently Server to function
MongoDB Node.js Driver Installation