Select Page
Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages
Filter by Categories
nmims post
Objective Type Set
Online MCQ Assignment
Question Solution
Solved Question
Uncategorized

MongoDB MCQ Set 1

1. \$sum is an accumulator operator available only in the _______ stage
a) \$group
b) \$sets
c) \$accumulator
d) None of the mentioned

Answer: a [Reason:] \$sum calculates and returns the sum of all the numeric values.

2. Point out the wrong statement :
a) \$avg is an accumulator operator available only in the \$group stage
b) \$sum accumulator can be used to compute the total amount and count for each group of documents
c) \$avg ignores numeric values
d) All of the mentioned

Answer: c [Reason:] \$avg returns the average value of the numeric values that result from applying a specified expression to each document in a group of documents that share the same group by key.

3. Which of the following ignores non numeric values ?
a) \$order
b) \$sum
c) \$asc
d) None of the mentioned

Answer: b [Reason:] \$sum returns a sum for each group. Ignores non-numeric values.

4. When using \$first in a \$group stage, the \$group stage should follow a _______ stage to have the input documents in a defined order.
a) \$order
b) \$sort
c) \$asc
d) None of the mentioned

Answer: b [Reason:] \$sort takes a document that specifies the field(s) to sort by and the respective sort order.

5. Point out the wrong statement :
a) \$weekDay returns the week number for a date as a number between 0 and 53 (leap year)
b) \$first is not meaningful when documents are in a defined order
c) \$first is an accumulator operator available only in the \$group stage
d) None of the mentioned

Answer: b [Reason:] \$first returns the value that results from applying an expression to the first document in a group of documents that share the same group by key.

6. Which of the following returns the value that results from applying an expression to the last document ?
a) \$end
b) \$last
c) \$max
d) All of the mentioned

Answer: b [Reason:] \$last has the following syntax: { \$last: }.

7. __________ returns the highest value from the group of values in documents.
a) \$end
b) \$last
c) \$max
d) \$maximum

Answer: c [Reason:] \$max returns the highest value that results from applying an expression to each document in a group of documents that share the same group by key.

8. Which of the following is syntax for calculating minimum value ?
a) { \$minimum: <int> }
b) { \$min: <expression>}
c) { \$minimum: <expression> }
d) None of the mentioned

Answer: b [Reason:] \$min returns the lowest value that results from applying an expression to each document in a group of documents that share the same group by key.

9. If all documents for the \$min operation have null value for the field or are missing the field, the \$min operator returns ____ for the minimum value.
a) 1
b) 0
c) null
d) none of the mentioned

Answer: c [Reason:] If some, but not all, documents for the \$min operation have either a null value for the field or are missing the field, the \$min operator only considers the non-null and the non-missing values for the field.

10. \$addToSet returns an array of all _______ values that results from applying an expression to each document.
a) unique
b) non unique
c) distinct
d) all of the mentioned

Answer: a [Reason:] Order of the elements in the output array is unspecified.

MongoDB MCQ Set 2

1. Which of the following code is used for successful exit of task ?
a) 0
b) 1
c) 2
d) 3

Answer: a [Reason:] 0 is returned by MongoDB applications upon successful exit.

2. Point out the correct statement :
a) 2 is returned by mongod if there is a mismatch between hostnames specified on the command line and in the local.sources collection
b) When an index covers a query, MongoDB can both match the query conditions and return the results using only the index keys
c) Both 2 and 4 are returned by mongod if there is a mismatch between hostnames specified on the command line and in the local.sources collection
d) All of the mentioned

Answer: a [Reason:] mongod may also return this status if oplog collection in the local database is not readable.

3. Instance exits cleanly is represented by ___ exit code
a) 4
b) 1
c) 2
d) 3

Answer: a [Reason:] Restart mongod with the –upgrade option to upgrade the database to the version supported by this mongod instance.

4. Which of the follwing code is returned by mongod if a moveChunk operation fails to confirm a commit ?
a) 5
b) 6
c) 7
d) 3

Answer: a [Reason:] Exit codes 6 and 7 does not exist.

5. Point out the correct statement :
a) Exit code 10 is for abnormal exit
b) 4 is returned when the version of the database is different from the version supported by the mongod (or mongod.exe) instance
c) The server socket is on port 27017 by default
d) None of the mentioned

Answer: b [Reason:] Exit code 10 is not in use.

6. Which of the following code represents exit cleanly following a large clock skew (32768 milliseconds) event ?
a) 45
b) 20
c) 47
d) 100

Answer: c [Reason:] 100 is returned by mongod when the process throws an uncaught exception.

7. 49 code is returned by mongod from _________ Service control Manager.
a) Linux
b) Windows
c) Ubuntu
d) All of the mentioned

Answer: a [Reason:] Custom read preferences and write concerns evaluate tags sets in different ways.

8. Which of the following code is returned when a MongoDB application cannot open a file ?
a) 45
b) 20
c) 47
d) 100

Answer: a [Reason:] 45 is returned when a MongoDB application cannot open a file or cannot obtain a lock on a file.

9. Identify the message returned by MongoDB applications for Windows due to failures installing ?
a) Message: ERROR: wsastartup failed
b) Message: NT Service Error
c) Message: wsastartup failed
d) None of the mentioned

Answer: b [Reason:] 20 is returned by MongoDB applications for Windows due to failures installing, starting or removing the NT Service for the application

10. Which of the following document represents uncaught exception ?
a) 45
b) 49
c) 47
d) 100

Answer: d [Reason:] 49 is returned by mongod.exe or mongos.exe on Windows when either receives a shutdown message from the Windows Service Control Manager.

MongoDB MCQ Set 3

1. ___________ concern describes the guarantee that MongoDB provides when reporting on the success of a write operation.
a) Write
c) Update
d) None of the mentioned

Answer: a [Reason:] The strength of the write concerns determine the level of guarantee.

2. Point out the correct statement :
a) Read operations on sharded clusters are most efficient when directed to a specific shard
b) Sharded clusters allow you to partition a data set among a cluster of mongod instances in a way that is nearly transparent to the application
c) For a sharded cluster, applications issue operations to one of the mongos instances associated with the cluster
d) All of the mentioned

Answer: d [Reason:] Queries to sharded collections should include the collection’s shard key.

3. When inserts, updates and deletes have a _________ write concern, write operations return quickly.
a) strong
b) weak
c) average
d) very strong

Answer: b [Reason:] With stronger write concerns, clients wait after sending a write operation for MongoDB to confirm the write operations.

4. The mongo shell and the MongoDB drivers use __________ as the default write concern.
a) Nacknowledged
b) Acknowledgement
c) Acknowledged
d) All of the mentioned

Answer: c [Reason:] MongoDB allows clients to read documents inserted or modified before it commits these modifications to disk, regardless of write concern level or journaling configuration.

5. Point out the wrong statement :
a) When a query does not include a shard key, the mongos can use cluster metadata from the config database to route the queries to shards
b) On larger clusters, scatter gather queries are unfeasible for routine operations
c) Replica sets use read preferences to determine where and how to route read operations to members of the replica set
d) None of the mwntioned

Answer: a [Reason:] If a query does not include the shard key, the mongos must direct the query to all shards in the cluster.

6. _____________ is used to control mongod commits in the journal.
a) commitIntervMs
b) commitInterval
c) commitIntervalMs
d) all of the mentioned

Answer: c [Reason:] For replica sets, write operations are durable only after a write replicates and commits to the journal on a majority of the voting members of the set.

7. Clients can set a __________ value as part of a replica acknowledged write concern.
a) timeout
b) wtimeout
c) waittimeout
d) none of the mentioned

Answer: b [Reason:] If the write concern is not satisfied in the specified interval, the operation returns an error, even if the write concern will eventually succeed.

8. MongoDB does not ___________ modifications made before the wtimeout interval expired.
a) commit
b) rollback
c) save
d) all of the mentioned

Answer: b [Reason:] he driver’s ability to detect network errors depends on the system’s networking configuration.

9. With an __________ write concern, MongoDB does not acknowledge the receipt of write operations.
a) Nacknowledged
b) Acknowledgement
c) Acknowledged
d) Unacknowledged

Answer: d [Reason:] Unacknowledged is similar to errors ignored.

10. With a receipt acknowledged write concern, the _________confirms that it received the write operation and applied the change to the in-memory view of data.
a) mongod
b) mongos
c) mongo
d) mongoc

Answer: a [Reason:] Acknowledged write concern allows clients to catch network, duplicate key, and other errors.

MongoDB MCQ Set 4

1. When you query a collection, MongoDB returns a ________ object that contains the results of the query.
a) row
b) cursor
c) colums
d) none of the mentioned

Answer: b [Reason:] The mongo shell then iterates over the cursor to display the results.

2. Point out the correct statement :
a) A database is a set of key-value pairs
b) A MongoDB deployment hosts a number of databases
c) A document holds a set of collections
d) All of the mentioned

Answer: b [Reason:] A database holds a set of collections. A collection holds a set of documents.

3. Which of the following method returns true if the cursor has documents ?
a) hasMethod()
b) hasNext()
c) hasDoc()
d) all of the mentioned

Answer: b [Reason:] hasNext() returns true if the cursor returned by the db.collection.find() query can iterate further to return more documents.

4. ____________ method renders the document in a JSON-like format.
a) displayjson
b) print
c) printjson
d) printdoc

Answer: c [Reason:] printjson() operation displays all documents.

5. Point out the wrong statement :
a) Documents have static schema in MongoDB
b) Eventually-consistent reads can be distributed over replicated servers
c) Indexes can include keys from embedded documents and arrays.
d) None of the mentioned

Answer: a [Reason:] Dynamic schema means that documents in the same collection do not need to have the same set of fields or structure, and common fields in a collection’s documents may hold different types of data.

6. Which of the following method is called while accessing documents using the array index notation ?
a) cur.toArray()
b) cursor.toArray()
c) doc.toArray()
d) all of the mentioned

Answer: b [Reason:] The toArray() method returns an array that contains all the documents from a cursor.

7. The mongo shell and the drivers provide several cursor methods that call on the cursor returned by the _______ method to modify its behavior.
a) cursor()
b) find()
c) findc()
d) none of the mentioned

8. Which of the following method corresponds to Order by clause in SQL ?
a) sort()
b) order()
c) orderby()
d) all of the mentioned

Answer: a [Reason:] The sort() method orders the documents in the result set.

9. The __________ method limits the number of documents in the result set.
a) limit()
b) limitOf()
c) limitBy()
d) none of the mentioned

Answer: a [Reason:] limit() corresponds to the LIMIT statement in SQL.

10. Which of the following line skips the first 5 documents in the bios collection and returns all remaining documents ?
a) db.bios.find().limit( 5 )
b) db.bios.find().skip( 1 )
c) db.bios.find().skip( 5 )
d) db.bios.find().sort( 5 )

Answer: c [Reason:] The skip() method controls the starting point of the results set.

MongoDB MCQ Set 5

1. Which of the following will implicitly create the collection testData ?
a)

```
while (var i = 1; i <= 25; i++)
{
db.testData.insert( { x : i } )
} ```

b)

```
for (var i = 1; i <= 25; i++)
{
db.testData.insert( { x : i } )
} ```

c)

```
for (var i = 1; i <= 25; i++)
{
db.testData.inserts( { x : i } )
} ```

d) None of the mentioned

Answer: b [Reason:] From the mongo shell, use the for loop. If the testData collection does not exist, MongoDB will implicitly create the collection.

2. Point out the correct statement :
a) Collection is a group of MongoDB documents
b) MongoDB is an open-source document database, and leading NoSQL database
c) Collections do not enforce a schema
d) All of the mentioned

Answer: a [Reason:] Documents within a collection can have different fields.

3. Which of the following method returns a cursor ?
a) find
b) sort
c) skip
d) all of the mentioned

Answer: a [Reason:] The find() method returns a cursor. To iterate the cursor and return more documents, type it in the mongo shell.

4. Which of the following function is valid for creation of new data inside MongoDB Shell ?
a)

```function insertData(dbName, colName, num)
{
var col = db.getSiblingDB(dbName).getCollection(colName);
for (i = 0; i < num; i++)
{
col.insertData({x:i});
}
print(col.count());
} ```

b)

```function insertData(dbName, colName, num)
{
var col = db.getSiblingDB(dbName).getCollection(colName);
for (i = 0; i < num; i++)
{
col.insert({x:i});
}
print(col.count());
} ```

c)

```
insertData(dbName, colName, num)
{
var col = db.getSiblingDB(dbName).getCollection(colName);
for (i = 0; i < num; i++)
{
col.insert({x:i});
}
print(col.count());
} ```

d) None of the mentioned

Answer: b [Reason:] insertData() JavaScript function that follows creates new data for use in testing or training by either creating a new collection or appending data to an existing collection:

5. Point out the wrong statement :
a) Database is a physical container for collections
b) A single MongoDB server typically has single databases
c) Collection is the equivalent of an RDBMS table
d) None of the mentioned

Answer: b [Reason:] A single MongoDB server typically has multiple databases.

6. _id is a ________ bytes hexadecimal number which assures the uniqueness of every document.
a) 13
b) 16
c) 12
d) 10

Answer: c [Reason:] You can provide _id while inserting the document.

7. Which of the following statement will insert 400 documents in to the testData collection ?
a) insertData("test", "testData", 200)
b) insertData("test", "testData", 400)
c) insertData("test", "testData", 600)
d) all of the mentioned

Answer: b [Reason:] If the collection and database do not exist, MongoDB creates them implicitly before inserting documents.

8. The mongo shell loads and parses the ___________ file on startup.
a) mongo.js
b) mongoc.js
c) mongorc.js
d) all of the mentioned

9. To iterate the cursor and return more documents, type _________ in the mongo shell.
a) cursor
b) it
c) next
d) none of the mentioned