Dbms Assignment 9
Dbms Assignment 9
Assignment No: 9
Class: T.E. Computer Roll No:
Problem Statement:
Study of Open Source NOSQL Database: MongoDB (Installation, Basic CRUD operations,
Execution)
Objective:
1. To learn and understand NOSQL Database.
2. To execute CRUD Operations on MongoDB.
Hardware requirements:
Any CPU with Pentium Processor or similar, 256 MB
RAM or more, 1 GB Hard Disk or more.
Software requirements:
Ubuntu 14.04, Mongodb Packages
Theory:
MongoDB is a free and open-source NoSQL document database used commonly in modern web
applications. MongoDB works on concept of collection and document.
Collection
Collection is a group of MongoDB documents. It is the equivalent of an RDBMS table. A
collection exists within a single database. Collections do not enforce a schema.
Document
A document is a set of key-value pairs. Documents have dynamic schema. Dynamic schema
means that documents in the same collection do not need to have the same set of fields or
structure, and common fields in a collection's documents may hold different types of data.
CRUD Operations:
Create Operations
Create or insert operations add new documents to a collection. If the collection does not currently
exist, insert operations will create the collection.
db.collection.insert()
Syntax:
db.collection.insert(
writeConcern: <document>,
ordered: <boolean>
e.g.
Read Operations
Read operations retrieves documents from a collection; i.e. queries a collection for documents.
MongoDB provides the following methods to read documents from a collection:
db.collection.find()
You can specify query filters or criteria that identify the documents to return.
Examples
The find() method with no parameters returns all documents from a collection and returns all fields
for the documents. For example, the following operation returns all documents in the bios
collection:
db.bios.find()
To find documents that match a set of selection criteria, call find() with the <criteria> parameter.
The following operation returns all the documents from the collection products where qty is greater
than 25:
Update Operations
Syntax
The basic syntax of update() method is as follows −
>db.COLLECTION_NAME.update(SELECTION_CRITERIA, UPDATED_DATA)
Example
Consider the mycol collection has the following data.
Following example will set the new title 'New MongoDB Tutorial' of the documents whose title is
'MongoDB Overview'.
By default, MongoDB will update only a single document. To update multiple documents, you
need to set a parameter 'multi' to true.
>db.mycol.update({'title':'MongoDB Overview'},
{$set:{'title':'New MongoDB Tutorial'}},{multi:true})
Delete Operation:
Syntax
Basic syntax of remove() method is as follows −
>db.COLLECTION_NAME.remove(DELLETION_CRITTERIA)
Example
Consider the mycol collection has the following data.
{ "_id" : ObjectId(5983548781331adf45ec5), "title":"MongoDB Overview"}
{ "_id" : ObjectId(5983548781331adf45ec6), "title":"NoSQL Overview"}
{ "_id" : ObjectId(5983548781331adf45ec7), "title":"Tutorials Point Overview"}
Following example will remove all the documents whose title is 'MongoDB Overview'.
>db.mycol.remove({'title':'MongoDB Overview'})
>db.mycol.find()
{ "_id" : ObjectId(5983548781331adf45ec6), "title":"NoSQL Overview"}
{ "_id" : ObjectId(5983548781331adf45ec7), "title":"Tutorials Point Overview"}
>
>db.COLLECTION_NAME.remove(DELETION_CRITERIA,1)
>db.mycol.remove()
>db.mycol.find()
>
Conclusion:
Oral Questions:
1)Difference between SQL & NoSQL.
2) Which are features of NoSQL Database.
3)Which are different types of NoSQL Database( Refer 6th unit)
4)How to insert record in mongodb collection with _id & without _id.
5)how to display document having item name as ‘pen’ from products database.