This set of MongoDB Multiple Choice Questions & Answers (MCQs) focuses on “Pipeline and Sharded Collections”.
1. Which of the following returns a substring of a string?
a) $subs
b) $substring
c) $substr
d) None of the mentioned
View Answer
Explanation: $substr accepts three expressions as arguments: the first argument must resolve to a string, and the second and third arguments must resolve to integers.
2. Point out the correct statement.
a) $substr ends at a specified index position up to a specified length
b) $toLower converts a string to lowercase
c) $gtle returns true if the first value is greater than or equal to the second
d) All of the mentioned
View Answer
Explanation: If the argument resolves to null, $toLower returns an empty string “”.
3. Which of the following accepts a single argument expression?
a) $toLow
b) $toUpper
c) $toEqual
d) None of the mentioned
View Answer
Explanation: $toUpper converts a string to uppercase.
4. Which of the following performs case-insensitive string comparison?
a) $strcasecmpequals
b) $strcasecmp
c) $strcmp
d) None of the mentioned
View Answer
Explanation: $strcasecmp returns 0 if two strings are equivalent.
5. Point out the wrong statement.
a) { $meta: “textScore” } expression is only meaningful in a pipeline that includes a $match stage with a $text query
b) The { $meta: “textScore” } expression is the only expression that the $sort stage accepts
c) $toLower only has a well-defined behavior for strings of ASCII characters
d) None of the mentioned
View Answer
Explanation: A $meta expression has the following syntax:{ $meta: <metaDataKeyword> }.
6. _______ is used for access text search metadata.
a) $text
b) $metades
c) $meta
d) All of the mentioned
View Answer
Explanation: $meta returns the metadata associated with a document in a pipeline operations.
7. Which of the following accepts named parameters?
a) $reduce
b) $letnum
c) $let
d) None of the mentioned
View Answer
Explanation: $let defines variables for use within the scope of a subexpression and returns the result of the subexpression.
8. _______ returns the number of elements in the array.
a) $number
b) $size
c) $div
d) None of the mentioned
View Answer
Explanation: The argument for $size can be any expression as long as it resolves to an array.
9. _________ returns a value without parsing.
a) $string
b) $literal
c) $characters
d) None of the mentioned
View Answer
Explanation: Use for values that the aggregation pipeline may interpret as an expression.
10. db.collection.aggregate() returns a _______ and can return result sets of any size.
a) replica
b) cursor
c) document
d) $subtract
View Answer
Explanation: The aggregate command can return results as a cursor or store the results in a collection, which are not subject to the size limit.
Sanfoundry Global Education & Learning Series – MongoDB.
Here’s the list of Best Books in MongoDB.
- Apply for Programming Internship
- Practice Programming MCQs
- Check MongoDB Books
- Check Information Technology Books