Unit 3 Two Marks
Unit 3 Two Marks
MONGO DB
PART-A
NoSQL stands for not only SQL. It is nontabular database system that store data differently than
relational tables. There are various types of NoSQL databases such document, key-value, wide
column and graph.Using NoSQL we can maintain flexible schemas and these schemas can be
scaled easily with large amount of data.
2) It is either schemas free or have relaxed schema. That means it does not require specific
definition of schema.
5) MongoDB provides high availability and redundancy with the help of replication
That means it creates multiple copies of the data and sends these copies to a different server so
that if one server fails, then the data is retrieved from another server.
The terms in SQL are treated differently in MongoDB. In MongoDB the data is not stored in
tables, instead of that, the there is a concept called collection which is analogous to the tables. In
the same manner the rows in RDBMS are called documents in MongoDB. likewise Q.5 Explain
the createUser command in MongoDB the columns of the record in RDBMS are called fields.
Syntax
dh.createUser(user, writeConcern)
Parameters
user: Is a document with authentication and access information about the user to create.
writeConcern: This document represents the level of write concern for creation operation.
Syntax
dis dropUser(username)
1) Integer: This data type is used for storing the numerical value
2) Boolean: This data type is used for implementing the Boolean values Le true or false
4) String: This is the most commonly used data type used for storing the string values.
5) Min/Max keys: This data type is used to compare a value against the lowest of highest
BSON element.
6) Arrays: For storing an array or list of multiple values in one key, this data type is used .
After creating some sample database we must create some collection males database.
db.createCollection(name.options)
where
options is an optional field. This field is used to specify some parameters such as size, maximum
number of documents and so on.
>var =allStudent=
[{
'name': AAA.
"age”: 20},
"name": BBB,
"age”: 21},
"name": CCC,
“ age” 22
},
];
>db.Student details.insert(allStudents);
The MongoDBClient object provides interactions to connect to the database. Following are some
commonly used method of MongoDBClient object.
Method
connect(url.options)
close(force, callback)
db(dbname, options)
isConnected(options)
Purpose
This method is used to connect to the MongoDB using the specified url.
Map reduce is a data processing programming model that helps in performing operations large
data sets and produce aggregate results. A Map reduce is used for large volume of data. The
syntax for map reduce is
1) map function: It uses emit() function in which it takes two parameters key and value key.
Here the key is on which we make groups(such as group by name, or age) and the second
parameter is on which aggregation is performed like avg(), sum() is calculated on.
2) reduce function: This is a function in which we perform aggregate functions like avg().
3) out: It will specify the collection name where the result will be stored.
syntax:
db.<collection>.createIndex({KEY:1})
Q.13 What are the datatypes in mongodb?
Integer: This data type is used for sorting the numerical value.\
Null: For sorting the null values this data type is used.
For updating the document we have to provide some criteria based on which the document can
be updated.
Syntax:
Db.collection_name.update(criteria,update_data)