Viva Questions
Viva Questions
• 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).
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:
Example:
> db.users.find({"age" : 24})
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})
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
}
The basic method for adding data to MongoDB is “inserts”. To insert a single
document, use the collection’s insertOne method:
For inserting multiple documents into a collection, we use insertMany. This method
enables passing an array of documents to the database.
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.
$ mongod
$ mongo
MongoDB shell version: 4.2.0
connecting to: test
>
> x = 100;
200
> x / 5;
20
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
True
False
Relational
document
Command
Object
C++
JavaScriot
Python
All of the mentioned above
Collections
Rows
Table
All of the mentioned