0% found this document useful (0 votes)
9 views7 pages

Viva Questions

MongoDB is an open-source NoSQL database that uses JSON-like documents and offers easy scalability. It supports dynamic schemas, various data types, and provides features like indexing, aggregation, and sharding. MongoDB is ideal for applications requiring rapid development and the ability to handle large volumes of data efficiently.

Uploaded by

apppozx123
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)
9 views7 pages

Viva Questions

MongoDB is an open-source NoSQL database that uses JSON-like documents and offers easy scalability. It supports dynamic schemas, various data types, and provides features like indexing, aggregation, and sharding. MongoDB is ideal for applications requiring rapid development and the ability to handle large volumes of data efficiently.

Uploaded by

apppozx123
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
You are on page 1/ 7

What is MongoDB ?

• MongoDB is an open-source NoSQL database written in C++ language. It uses


JSON-like documents with optional schemas.
• It provides easy scalability and is a cross-platform, document-oriented database.
• MongoDB works on the concept of Collection and Document.
• It combines the ability to scale out with features such as secondary indexes, range
queries, sorting, aggregations, and geospatial indexes.
• MongoDB is developed by MongoDB Inc. and licensed under the Server Side
Public License (SSPL).

MongoDB Basic Questions


1. What are some of the advantages of MongoDB?

Some advantages of MongoDB are as follows:

• MongoDB supports field, range-based, string pattern matching type queries. for
searching the data in the database
• MongoDB support primary and secondary index on any fields
• MongoDB basically uses JavaScript objects in place of procedures
• MongoDB uses a dynamic database schema
• MongoDB is very easy to scale up or down
• MongoDB has inbuilt support for data partitioning (Sharding).

2. When to use MongoDB?

You should use MongoDB when you are building internet and business
applications that need to evolve quickly and scale elegantly. MongoDB is popular
with developers of all kinds who are building scalable applications using agile
methodologies.
MongoDB is a great choice if one needs to:

• Support a rapid iterative development.


• Scale to high levels of read and write traffic - MongoDB supports horizontal scaling
through Sharding, distributing data across several machines, and facilitating high
throughput operations with large sets of data.
• Scale your data repository to a massive size.
• Evolve the type of deployment as the business changes.
• Store, manage and search data with text, geospatial, or time-series dimensions.

3. What are the data types in MongoDB?

MongoDB supports a wide range of data types as values in documents. Documents


in MongoDB are similar to objects in JavaScript. Along with JSON’s essential
key/value–pair nature, MongoDB adds support for a number of additional data
types. The common data types in MongoDB are:
• Null
{"x" : null}
• Boolean
{"x" : true}
• Number
{"x" : 4}
• String
{"x" : "foobar"}
• Date
{"x" : new Date()}
• Regular expression
{"x" : /foobar/i}
• Array
{"x" : ["a", "b", "c"]}
• Embedded document
{"x" : {"foo" : "bar"}}
• Object ID
{"x" : ObjectId()}
• Binary Data
Binary data is a string of arbitrary bytes.
• Code
{"x" : function() { /* ... */ }}

4. How to perform queries in MongoDB?

The find method is used to perform queries in MongoDB. Querying returns a


subset of documents in a collection, from no documents at all to the entire
collection. Which documents get returned is determined by the first argument
to find, which is a document specifying the query criteria.

Example:
> db.users.find({"age" : 24})

5. How do you Delete a Document?

The CRUD API in MongoDB provides deleteOne and deleteMany for this purpose.
Both of these methods take a filter document as their first parameter. The filter
specifies a set of criteria to match against in removing documents.

For example:
> db.books.deleteOne({"_id" : 3})

6. How do you Update a Document?

Once a document is stored in the database, it can be changed using one of several
update methods: updateOne, updateMany, and replaceOne.
updateOne and updateMany each takes a filter document as their first parameter and
a modifier document, which describes changes to make, as the second
parameter. replaceOne also takes a filter as the first parameter, but as the second
parameter replaceOne expects a document with which it will replace the document
matching the filter.
For example, in order to replace a document:

{
"_id" : ObjectId("4b2b9f67a1f631733d917a7a"),
"name" : "alice",
"friends" : 24,
"enemies" : 2
}

7. How to add data in MongoDB?

The basic method for adding data to MongoDB is “inserts”. To insert a single
document, use the collection’s insertOne method:

> db.books.insertOne({"title" : "Start With Why"})

For inserting multiple documents into a collection, we use insertMany. This method
enables passing an array of documents to the database.

8. What are some features of MongoDB?

• Indexing: It supports generic secondary indexes and provides unique, compound,


geospatial, and full-text indexing capabilities as well.
• Aggregation: It provides an aggregation framework based on the concept of data
processing pipelines.
• Special collection and index types: It supports time-to-live (TTL) collections for
data that should expire at a certain time
• File storage: It supports an easy-to-use protocol for storing large files and file
metadata.
• Sharding: Sharding is the process of splitting data up across machines.

9. How does Scale-Out occur in MongoDB?

The document-oriented data model of MongoDB makes it easier to split data


across multiple servers. Balancing and loading data across a cluster is done by
MongoDB. It then redistributes documents automatically.

The mongos acts as a query router, providing an interface between client


applications and the sharded cluster.

Config servers store metadata and configuration settings for the cluster. MongoDB
uses the config servers to manage distributed locks. Each sharded cluster must
have its own config servers.
10. What is the Mongo Shell?

It is a JavaScript shell that allows interaction with a MongoDB instance from the
command line. With that one can perform administrative functions, inspecting an
instance, or exploring MongoDB.

To start the shell, run the mongo executable:

$ mongod
$ mongo
MongoDB shell version: 4.2.0
connecting to: test
>

The shell is a full-featured JavaScript interpreter, capable of running arbitrary


JavaScript programs. Let’s see how basic math works on this:

> x = 100;
200
> x / 5;
20

11. What are Databases in MongoDB?

MongoDB groups collections into databases. MongoDB can host several


databases, each grouping together collections.
Some reserved database names are as follows:
admin
local
config

12. What is a Collection in MongoDB?

A collection in MongoDB is a group of documents. If a document is the MongoDB


analog of a row in a relational database, then a collection can be thought of as the
analog to a table.
Documents within a single collection can have any number of different “shapes.”,
i.e. collections have dynamic schemas.
For example, both of the following documents could be stored in a single collection:

{"greeting" : "Hello world!", "views": 3}


{"signoff": "Good bye"}

13. What is a Document in MongoDB?

A Document in MongoDB is an ordered set of keys with associated values. It is


represented by a map, hash, or dictionary. In JavaScript, documents are
represented as objects:
{"greeting" : "Hello world!"}

Complex documents will contain multiple key/value pairs:


{"greeting" : "Hello world!", "views" : 3}

MongoDB MCQ
1. MongoDB also supports user-defined indexes on multiple fields called ____________
compound
composite
candidate
none of the above
2. Which of the following does not come under the basic shell operations on
MongoDB?
Update
Create
Delete
Write
3. Which of these is not a built-in role that grants permissions for database users in
MongoDB?
read
readWrite
dbOwner
write
4. MongoDB indexes use a ___ data structure.
Hash
Map
B-tree
All of the above
5. A _________ key is either an indexed field or an indexed compound field that exists in
every document in the collection.
cluster
shard
partition
all of the above
6. With hash-based partitioning, two documents with _____ shard key values are
unlikely to be part of the same chunk.
open
close
partially close
all of the above
7. All of the following are properties of Sharding, except:
Sharding refers to the process of splitting data up across machines.
Sharding in turn requires larger and more powerful machines
Manual sharding can be done with almost any database software.
Sharding is the most complex way of configuring MongoDB
8. Which of the following statements is true?
To shard a document, one needs to select a shard key.
MongoDB divides the shard key values into replica sets.
MongoDB distributes data, or shards, at the collection level.
All of the above are true.
9. MongoDB Queries can return specific fields of documents which also include user-
defined __________ functions.
Javascript
C
C++
All of the mentioned
10. ____________ are operations that process data records and return computed results.
ReplicaAgg
SumCalculation
Aggregations
None of the above
11. The most basic pipeline stages provide __________ that operate like queries.
methods
filters
stored procedure
none of the above
12. MongoDB stores the documents in what are called _____________
tables
collections
rows
all of the above
13. Which of the following is not a data type supported by MongoDB?
Code
ID
Date
String
14. A collection in MongoDB is a group of ...….

Databases
Schema
Related Documents
Rows

15. Does MongoDB support linux?

True
False

16. MongoDB is a ..... type database?

Relational
document
Command
Object

17. MongoDB is written in ....................

C++
JavaScriot
Python
All of the mentioned above

18. MongoDB stores all documents in _______

Collections
Rows
Table
All of the mentioned

19. Out of the following commands in MongoDB executes the query:

SELECT * FROM posts WHERE writer like "%ashish%"


db.docs.find( { writer: /ashish/ } )
db.docs.find( { writer: {$like: /ashish/} } )
db.docs.find( { $like: {writer: /ashish/} } )
db.docs.find( { writer: /^ashish^/ } )

20. What kind of database is MongoDB?

MongoDB is a NoSQL database.


MongoDB is a SQL database.
MongoDB is a Relational database.
MongoDB is a Non-relational database

You might also like