Adbms Unit 2
Adbms Unit 2
MANAGEMENT
SYSTEM
UNIT-2
UNIT-II
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