0% found this document useful (0 votes)
9 views4 pages

Mongo DB

Uploaded by

Suresh Naidu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

Mongo DB

Uploaded by

Suresh Naidu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

MONGODB manual

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

Syntax: use database_name


Ex: use mydb

EXP-3
Creating the collection in MongoDB on the fly
Create Collection: To create a collection

Syntax: db.createCollection(“ Collection_name“)


Ex: db.createCollection(“faculty”)

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

a) Insert single document:To insert a single document we use insertOne() method

Ex:db.faculty.insert({name:"Akbar",age:47})
Syntax:db.collectionname.insertOne({document})
Ex:db.students.insertOne({name:"lakshmi",age:19})

b) Insert multiple documents: To insert multiple documents we use insertMany() method


Syntax:db.collectionname.insertMany([document1,document2,…])
Ex:db.students.insertMany([{name:"Sri",age:19,roll:18},{name:"Anil",age:65,roll:80}])
Ex:db.faculty.insertMany([{name:"manasa",fullTime:"True"},{name:"Bushra",fullTime:"True"},
{name:”sirisha”,fullTime:”False”}])
Retrieve data:To retrieve data from a MongoDB collection,we use find() method
Syntax:db.collectionname.find()
Ex:db.students.find()

EXP-6
Querying all the document in json format and Querying based on the criteria.

Quering based on criteria


Syntax:db.collectionname.find({criteria})
Ex:db.students.find({name:"Sri"})

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})

You might also like