0% found this document useful (0 votes)
944 views38 pages

Adbms Unit 2

This document provides an overview of MongoDB, including its installation process, basic operations, and data types. It highlights MongoDB's document-oriented structure, ease of scaling, and various features such as indexing and aggregation. Additionally, it details CRUD operations and the specific commands used to interact with MongoDB databases and collections.

Uploaded by

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

Adbms Unit 2

This document provides an overview of MongoDB, including its installation process, basic operations, and data types. It highlights MongoDB's document-oriented structure, ease of scaling, and various features such as indexing and aggregation. Additionally, it details CRUD operations and the specific commands used to interact with MongoDB databases and collections.

Uploaded by

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

ADVANCED DATA BASE

MANAGEMENT
SYSTEM
UNIT-2
UNIT-II

• Introduction MongoDB: MongoDb Installation, Basics of


MongoDb, MongoDb Shell, MongoDb Datatypes, MongoDb
CRUD operations: Adding new documents to a collection,
Selecting documents, updating existing documents,
Removing documents from a collection.
Basics of MongoDB
 Ease of Use
 MongoDB is a document-oriented database, not a relational one. The primary reason for
moving away from the relational model is to make scaling out easier, but there are some
other advantages as well.
 A document-oriented database replaces the concept of a “row” with a more flexible model,
the “document.
 There are also no predefined schemas: a document’s keys and values are not of fixed types
or sizes.
 Easy Scaling
 Data set sizes for applications are growing at an incredible pace. Increases in available
bandwidth and cheap storage have created an environment where even small-scale ap‐
plications need to store more data than many databases were meant to handle
 As the amount of data that developers need to store grows, developers face a difficult
decision.
 MongoDB was designed to scale out. Its document-oriented data model makes it easier for it
to split up data across multiple servers.
Basics of MongoDB
 Tons of Features
 MongoDB is intended to be a general-purpose database, so aside from creating, reading,
updating, and deleting data, it provides an ever-growing list of unique features:
 Indexing
 MongoDB supports generic secondary indexes, allowing a variety of fast queries, and
provides unique, compound, geospatial, and full-text indexing capabilities as well.
 Aggregation
 MongoDB supports an “aggregation pipeline” that allows you to build complex
aggregations from simple pieces and allow the database to optimize it.
Basics of MongoDB

 Special collection types


 MongoDB supports time-to-live collections for data that should expire at a certain time,
such as sessions. It also supports fixed-size collections, which are useful for holding recent
data, such as logs.
 File storage
 MongoDB supports an easy-to-use protocol for storing large files and file metadata. Some
features common to relational databases are not present in MongoDB, notably joins and
complex multirow transactions.
 Omitting these was an architectural decision to allow for greater scalability, as both of
those features are difficult to provide efficiently in a distributed system.
MongoDB Installation
 Requirements to Install MongoDB on Windows
 MongoDB 4.4 and later only support 64-bit versions of Windows
 MongoDB 8.0 Community Edition supports the following 64-bit versions of Windows on
x86_64 architecture.
 Windows Server 2022
 Windows Server 2019
 Windows 11
 Mongodb exhibited two facilities by following.
 1. Mongod –Mongo db graphical version for users
 2. Mongosh – command propt for Mongodb users.
MongoDB Installation(GUI)
 Steps to Install MongoDB on Windows
 Step 1: Go to the MongoDB Download Center to download the MongoDB Community Server.
MongoDB Installation(GUI)
 Steps to Install MongoDB on Windows
 Step 2: When the download is complete open the msi file and click the next button in the
startup screen.
MongoDB Installation(GUI)
 Steps to Install MongoDB on Windows
 Step 3: Now accept the End-User License Agreement and click the next button:
MongoDB Installation(GUI)
 Steps to Install MongoDB on Windows
 Step 4: Now select the complete option to install all the program features. Here, if you can
want to install only selected program features and want to select the location of the installation,
then use the Custom option:
MongoDB Installation(GUI)
 Steps to Install MongoDB on Windows
 Step 5: Select “Run service as Network Service user” and copy the path of the data
directory. Click Next:
MongoDB Installation(GUI)
 Steps to Install MongoDB on Windows
 Step 6: Click the Install button to start the MongoDB installation process:
MongoDB Installation(GUI)
 Steps to Install MongoDB on Windows
 Step 7: clicking on the install button installation of MongoDB begins:
MongoDB Installation(GUI)
 Steps to Install MongoDB on Windows
Step 8: clicking Now click the Finish button to complete the MongoDB installation process:
Step 9: Now we go to the location where MongoDB installed in step 5 in your system and copy
the bin path
MongoDB Installation(GUI)
 Steps to Install MongoDB on Windows
Step 8: clicking Now click the Finish button to complete the MongoDB installation process:
Step 9: next install the mongodb shell by following simple steps.
Step9.1: Go to the MongoDB Download Center (tools – monogo DB shell)
MongoDB Installation(GUI)
 Steps to Install MongoDB on Windows
Step9.2: Download the Zip version and store the unzip file in to C:\Program Files\MongoDB
Step 9.3: Edit the Environment variables by adding the mongosh into the system variables
Step9.4: Go to the location where MongoSh installed system and copy the bin path:
MongoDB Installation(GUI)
 Steps to Install MongoDB on Windows
Step 10: Open the command prompt and type monogosh path and complete the installation
process.
MongoDB Installation(GUI)
MongoDB Shell Commands
 Sample MongoDB commands
 To print all the existed databases in mongodb use the following command
 show dbs
 To shift the new database from old database in mongodb use the following command
 Use new database name
 To create a collection in the existed databases of mongodb use the following command
 databasename.createCollection(‘name of collection’)
 To insert new instruction in the existed database of mongodb use the following command
 databasename.collectionname.insertOne(attribute fields)
 Example:

 To find the data from the existed database of mongodb use the following command
 databasename.createCollection. Find()
 Example:
MongoDB CRUD operations
CRUD (CREATE, READ, UPDATE & DELETE)
 Adding new database to a collection
 Open the Mongodb Compass GUI platform
 Select the localhost:27017
 Click on create database
MongoDB CRUD operations
 Adding new database to a collection
 Give the Database name
 Mention the Collection name also
 Click on create database
MongoDB CRUD operations
 Adding new database to a collection
 See the updated databases on the localhost:27017 new data base and collection included
MongoDB CRUD operations
 Adding new collection to existed database
 Click on the + mark on right side of the existed database name in locahost:27017
 A new winos opened to enter the new collection details in the existed databse
MongoDB CRUD operations
 Adding new collection to existed database
 See the added collection in the databases by click on the existed data base which is in the localhost:27017
MongoDB CRUD operations
 Removing documents from a collection
 For database –click on recycle bin button which is existed on right side of database name in local host:27017 and
type database name in window.
MongoDB CRUD operations
 Removing documents from a collection
 For individual collection –click on recycle bin button which is existed on right side of opened collection in data
base of local host:27017 and type collection name.
MongoDB CRUD operations
 Removing documents from a collection
 For individual collection –click on recycle bin button which is existed on right side of opened collection in data
base of local host:27017
MongoDB CRUD operations
 Update document data from a collection
 For update on document–double click on intended field of document and click on update button right side of
opened collection in data base of local host:27017
MongoDB Data types
 In MongoDB, the documents are stored in BSON, which is the binary encoded format of JSON and
using BSON we can make remote procedure calls in MongoDB. BSON data format supports various
data types.
 MongoDB supports a wide range of data types, from strings to arrays.
 1. String
 This is the most commonly used data type in MongoDB to store data, BSON strings are of UTF-8
(Unicode Transformation). So, the drivers for each programming language convert from data types to
the string format of the language to UTF-8 while serializing and de-serializing BSON. The string must
be a valid UTF-8. Ex: “name”: ”SS”
 String with multiple ids :
MongoDB Data types
 2. Integer
 In MongoDB, the integer data type is used to store an integer value. We can store integer data type in
two forms 32-bit signed integer and 64-bit signed integer. Ex: “no”:16
 3. Double
 The double data type is used to store the floating-point values. Ex: “avg” :54.6789
 4. Boolean
 The Boolean data type is used to store either true or false.
 Example: storing the final result of the student as pass or fail in Boolean values. Ex: “Pass” : true
 5. Undefined
 This data type stores the undefined values.
MongoDB Data types
 6. Null
The null data type is used to store the null value.
Example: the student does not have a mobile number so the number field contains the value null.
Ex: “mobile”: null
 7. Object
Object data type stores embedded documents. Embedded documents are also known as nested documents.
Embedded document or nested documents are those types of documents which contain a document inside
another document.
{ "name":"s1","age":25,"number":12,"rank":1,"avg":87.89,
"marks":{"m1":76,"m2":87,"m3":98,"result":"pass"}}


MongoDB Data types
 8. Object Id
 new document in the collection MongoDB automatically creates a unique object id for that document
(if the document does not have it).
 There is an _id field in MongoDB for each document. The data which is stored in Id is of hexadecimal
format and the length of the id is 12 bytes which consist:
 4-bytes for Timestamp value.
 5-bytes for Random values. i.e., 3-bytes for machine Id and 2-bytes for process Id.
 3- bytes for Counter
 Create our own id field is possible, but make sure that the value of that id field must be unique.
 9. Undefined
 This data type stores the undefined values. “p1”:”undefined”
 10. Binary Data
 This datatype is used to store binary data.
 Example: the value stored in the binaryValue field is of binary type. “binaryvalue”:”10001001”
MongoDB Data types
 11.Date

 data type stores date. It is a 64-bit integer which represents the number of milliseconds.
 BSON data type generally supports UTC datetime and it is signed.
 If the value of the date data type is negative then it represents the dates before 1970.
 There are various methods to return date, it can be returned either as a string or as a date object.
 Some method for the date:
 Date(): It returns the current date in string format.
 new Date(): Returns a date object. Uses the ISODate() wrapper.
 new ISODate(): It also returns a date object. Uses the ISODate() wrapper.
MongoDB Data types
 12. Min & Max key
 Min key compares the value of the lowest BSON element and Max key compares the value
against the highest BSON element. Both are internal data types.

 13. Symbol
 This data type similar to the string data type. It is generally not supported by a mongo shell,
but if the shell gets a symbol from the database, then it converts this type into a string type.
MongoDB Data types
 14. Decimal
 new document in the collection MongoDB automatically creates a unique object id for that document
(if the document does not have it).

 15. Timestamp
 this data type is used to store a timestamp. It is useful when we modify our data to keep a record and the
value of this data type is 64-bit. The value of the timestamp data type is always unique.
MongoDB Data types
 16. Regular Expression
 This datatype is used to store regular expressions.

 17. Array
 The Array is the set of values. It can store the same or different data types values in it. In MongoDB, the
array is created using square brackets([]).
MongoDB Update Document
 Update Document
 This datatype is used to store regular expressions.
 To update an existing document we can use the updateOne() or updateMany() methods.
 The first parameter is a query object to define which document or documents should be updated.
 The second parameter is an object defining the updated data.
 Update One
 Method will update the first document that is found matching the provided query
MongoDB Update Document
 Update Many
 Method will update all documents that match the provided query

You might also like