Mongo DB
Mongo DB
EXP-1
MongoDB installation and configuration in windows.
EXP-2
Demonostrate how to create and drop a database in mongoDB
Create Database: To create database
EXP-3
Creating the collection in MongoDB on the fly
Create Collection: To create a collection
EXP-4
Create collection with options before inserting the documents and drop the collection
created
Ex: db.clubs.insert({name:"workshop"})
Drop: Used to drop a collection
Syntax:db.dropDatabase()
Ex:Db.students.drop()
EXP-5
MongoDB Insert document
a) Insert single document
b) Insert multiple documents
Ex:db.faculty.insert({name:"Akbar",age:47})
Syntax:db.collectionname.insertOne({document})
Ex:db.students.insertOne({name:"lakshmi",age:19})
EXP-6
Querying all the document in json format and Querying based on the criteria.
EXP-7
MongoDB update document
a) Using update() method
b) Using save() method.
Update document: In MongoDB, we use update documents using the update One() or
updateMany() methods
a) update() method
syntax:db.colletionname.updateOne(criteria,update_data)
Ex: db.students.updateOne({name:"Sri"},{$set:{name:"Sreeja"}})
EXP-8
MongoDB delete document from a collection
a) Using remove() method
b) Remove only one ddocument matching your criteria
c) Remove all document
Delete:
In MongoDB,we can delete documents using the deleteOne() or deleteMany() methods.
Remove:
Remove only one document matching your criteria
Syntax:db.collectionname.deleteOne({“key”;”value”})
Ex:db.students.deleteOne({name:"lakshmi"})
Remove all documents
Syntax:db.collectionname.deleteMany({“key”;”value”})
Ex:db.faculty.deleteMany({fullTime:"True"})
EXP-9
Mongodb projection:
In MongoDB,projection allows you to specify which fields should be included or excluded in the
query results.
Syntax:db.collection.find({},{field1:1,field2:1})
Ex:db.students.find({},{_id:false,name:true})
EXP-10
Limit(),Skip() ,Sort() methods in MongoDB
sort():In MongoDB, we can sort query results using the sort() method.
1 specifies ascending order and -1 specifies descending order.
Syntax:db.collection.find().sort({field:1})//Ascending order
db.collection.find().sort({field:-1})//Descending order
Ex:db.faculty.find().sort({name:-1})
Ex:db.faculty.find().sort({name:1})