0% found this document useful (0 votes)
3 views8 pages

No SQL

The document outlines basic MongoDB operations, including creating and dropping databases and collections, as well as performing CRUD operations. It provides examples for inserting, querying, updating, and deleting documents, along with executing simple queries using conditions. Additionally, it demonstrates how to sort documents and find specific fields in the database.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views8 pages

No SQL

The document outlines basic MongoDB operations, including creating and dropping databases and collections, as well as performing CRUD operations. It provides examples for inserting, querying, updating, and deleting documents, along with executing simple queries using conditions. Additionally, it demonstrates how to sort documents and find specific fields in the database.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Practical No.

1: MongoDB Basics
Aim
To study basic MongoDB operations such as creating and dropping databases, collections,
and performing CRUD operations.

a) Create and Drop Database

Create Database

use collegeDB

Note: Database is created when data is inserted into a collection.

Drop Database

[Link]()

b) Create, Display and Drop Collection

Create Collection

[Link]("students")

Display Collections
show collections

Drop Collection

[Link]()

c) Insert, Query, Update and Delete a Document


Insert Document
[Link]({

rollNo: 1,

name: "Vikas",

age: 20,

marks: 85

})

Query Document

[Link]()

[Link]({ rollNo: 1 })

Update Document
[Link](

{ rollNo: 1 },

{ $set: { marks: 90 } }

Delete Document

[Link]({ rollNo: 1 })
Practical No. 2: Simple Queries with MongoDB
Aim
To perform simple queries in MongoDB using insert and find operations with conditions.

Procedure and Queries


Insert Multiple Documents
[Link]([

{ rollNo: 2, name: "Kaustubh", age: 20, marks: 85 },

{ rollNo: 3, name: "Dhananjay", age: 20, marks: 92 },

{ rollNo: 4, name: "Paras", age: 20, marks: 85 },

{ rollNo: 5, name: "Ajinkya", age: 19, marks: 78 }

])

Find All Documents


[Link]()

Find with Condition

[Link]({ marks: { $gt: 80 } })


Find Specific Fields

[Link]({},{ name: 1, marks: 1, _id: 0 })

Find Documents Using AND Condition

[Link]({ age: 20, marks: { $gt: 80 } })

Purpose: Displays students whose age is 20 and marks are greater than 80.

Find Documents Using OR Condition

[Link]({

$or: [

{ marks: { $gt: 90 } },

{ age: 19 }
]

})

Purpose: Displays students who have marks greater than 90 or age equal to 19.

Sort Documents

[Link]().sort({ marks: -1 })

Purpose: Displays students sorted by marks in descending order.

You might also like