Sunteți pe pagina 1din 26

MongoDB MCQ

Q 1 - What kind of database MongoDB is?


A - Graph Oriented
B - Document Oriented
C - Key Value Pair
D - Column Based

Q 2 - A collection and a document in MongoDB is equivalent to which of the SQL concepts
respectively?
A - Table and Row
B - Table and Column
C - Column and Row
D - Database and Table

Q 3 - Which of the following is correct about MongoDB?


A - MongoDB uses JSON format to represent documents
B - MongoDB supports collection joins
C - MongoDB supports some of the SQL functions
D - MongoDB supports geospatial indexes

Q 4 - Which of the following is a valid MongoDB JSON document:


A

{}

{
"user_id"=1,
"user_name"="Joe Sanders",
"occupation"=["engineer","writer"]
}
C

{
"user_id":1;
"user_name":"Joe Sanders";
"occupation":["engineer","writer"]
}

{
"user_id":1,
"user_name":"Joe Sanders",
"occupation":[
"occupation1":"engineer",
"occupation2":"writer"
]
}

Q 5 - Which of the following is correct explanation of MongoDB processes?


A - mongod.exe is the shell process and mongo.exe is the actual database process
B - mongo.exe is the shell process and mongod.exe is the actual database process
C - mongos.exe is the MongoDB server process needed to run database
D - mongodump.exe can be used to import database backup dump

Q 6 - Consider a collection posts which has fields: _id, post_text, post_author,
post_timestamp, post_tags etc. Which of the following query retrieves ONLY the key named
post_text from the first document retrieved?
A - db.posts.find({},{_id:0, post_text:1})
B - db.posts.findOne({post_text:1})
C - db.posts.finOne({},{post_text:1})
D - db.posts.finOne({},{_id:0, post_text:1})

Q 7 - Which of the following is incorrect statement about find and findOne operations in
MongoDB?
A - find() returns all the documents in a collection while findOne() retrieves only the first one.
B - find() and findOne() returns cursors to the collection documents
C - findOne() returns the actual first document retrieved from a collection
D - find.limit(1) is not the same query as findOne()
Q 8 - In a collection that contains 100 post documents, what does the following command
do?
db.posts.find().skip(5).limit(5)
A - Skip and limit nullify each other. Hence returning the first five documents.
B - Skips the first five documents and returns the sixth document five times
C - Skips the first five documents and returns the next five
D - Limits the first five documents and then return them in reverse order

Q 9 - Which of the following MongoDB query is equivalent to the following SQL query:
UPDATE users SET status = "C" WHERE age > 25
A

db.users.update(
{ age: { $gt: 25 } },
{ status: "C" })

db.users.update(
{ age: { $gt: 25 } },
{ $set: { status: "C" } })

db.users.update(
{ age: { $gt: 25 } },
{ $set: { status: "C" } },
{ multi: true })

db.users.update(
{ age: { $gt: 25 } },
{ status: "C" },
{ multi: true })

Q 10 - The MongoDB explain() method does not support which of the following verbosity
mode:
A - queryPlanner
B - executionStats
C - allPlansExecution
D - customExecutionStats

Q 11 - Which is the default mode in which the explain() command runs?
A - queryPlanner
B - executionStats
C - allPlansExecution
D - customExecutionStats

Q 12 - Within how much time does MongDB writes are written to the journal?
A - 60 s
B - 100 ms
C - 1 s
D - 100 s

Q 13 - Which of the following is true about sharding?


A - Sharding is enabled at the database level
B - Creating a sharded key automatically creates an index on the collection using that key
C - We cannot change a shard key directly/automatically once it is set up
D - A sharded environment does not support sorting functionality since the documents lie on
various mongod instances

Q 14 - What is the maximum size of a MongoDB document?


A - 2 MB
B - 16 MB
C - 12 MB
D - There is no maximum size. It depends on the RAM.

Q 15 - What is the maximum size of Index Key Limit and Number of Indexes per collection?
A - 64 bytes and 1024 indexes
B - 12 mega bytes and 64 indexes
C - 1024 bytes and 64 indexes
D - 1024 bytes and unlimited indexes

Q 16 - What is the output of the following program?


A - 60 s
B - 100 ms
C - 1 s
D - 100 s

Q 17 - Which of the following commands finds all the documents in the posts collection
with post timestamp field as null?
A - db.posts.find( { post_timestamp : { $type: 10 } } )
B - db.posts.find( { post_timestamp: { $type: null } } )
C - db.posts.find( { post_timestamp: { $fieldtype: 10 } } )
D - db.posts.find( { post_timestamp: { $fieldtype: null } } )

Q 18 - mongoimport command is used to:


A - import all the data from one database to another
B - import all the data from one collection to another
C - imports content from an Extended JSON, CSV, or TSV export created by mongoexport
D - import all the MongoDB data from one format to another

Q 19 - Which of the following command can be used in mongo shell to show all the
databases in your MongoDB instance?
A - show dbs
B - show databases
C - show dbs -all
D - ls dbs

Q 20 - Which of the following replica sets vote in the election of a primary replica set?
A - Secondary
B - Hidden
C - Delayed
D - All of the above

Q 21 - Which of the following command can be used to check the size of a collection named
posts?
A - db.posts.stats()
B - db.posts.findStats()
C - db.posts.find({stats:1})
D - db.stats({ collection : posts })

Q 22 - Which of the following commands can cause the database to be locked?
A - Issuing a query
B - Inserting data
C - Map-reduce
D - All of the above

Q 23 - By default, the MongoDB cursor in mongo shell is configured to return how many
documents? To get the next set of documents, which command is used?
A - 20, it
B - 200, more
C - 50, it
D - No limit, none

Q 24 - Which of the following commands will return all the posts with number of likes
greater than 100 and less than 200, both inclusive?
A - db.posts.find({ likes : { $gt : 100, $lt : 200 } } );
B - db.posts.find({ likes : { $gte : 100, $lt : 200 } } );
C - db.posts.find({ likes : { $gt : 100 , $lte : 200 } } );
D - db.posts.find({ likes : { $gte : 100 , $lte : 200 } } );

Q 25 - In our posts collection, which command can be used to find all the posts whose
author names begin lie between �A� and �C� in dictionary order?
A - db.posts.find( { post_author : { $gte : "A" , $lte : "C" } } );
B - db.posts.find( { post_author : { $gte : "C" , $lte : "A" } } );
C - db.posts.find( { post_author : { $gt : "A" , $lt : "C" } } );
D - This type of search is not supported by MongoDB. $lt and $gt operators are applicable only
for numeric values.

Q 26 - What does the following MongoDB command return?


db.posts.find( { likes : { $gt : 100 }, likes : { $lt : 200 } } );
A - Posts with likes greater than 100 but less than 200
B - Posts with likes greater than or equal to 100 but less than or equal to 200
C - Posts with likes less than 200
D - Will return syntax error

Q 27 - Consider that our posts collection contains an array field called tags that contains tags
that the user enters.

{
_id: 1,
tags: [�tutorial�, �fun�, �learning�],
post_text: �This is my first post�,
//other elements of document
}

Which of the following commands will find all the posts that have been tagged as tutorial.
A - db.posts.find( { tags : "tutorial" } );
B - db.posts.find( { tags : ["tutorial"] } );
C - db.posts.find( { $array : {tags: "tutorial"} } );
D - db.posts.findInArray( { tags : "tutorial" } );

Q 28 - Which of the following is the most important consideration while designing the
schema for MongoDB?
A - The schema should match the data access and query patterns
B - The schema should be kept in 3NF similar to SQL schemas
C - The schema should focus on creating possible embedded documents
D - The schema should contain maximum indexes

Q 29 - Which of the following operations on a single document will operate atomically?
A - update
B - $push
C - Both a and b
D - None of the above

Q 30 - Which of the following is supported by MongoDB?


A - ACID Transactions
B - Relationships between Collections (Primary Key � Foreign Key)
C - Journaling
D - Transaction Management

Q 31 - Consider that our posts collection contains an array field called tags that contains tags
that the user enters.

{
_id: 1,
tags: [�tutorial�, �fun�, �learning�],
post_text: �This is my first post�,
//other elements of document
}

What does the following command return:


db.posts.find( { 'tags.0': �tutorial� } )
A - All the posts whose tags array contains tutorial
B - All the posts which contains only one tag element in the tag array
C - All the posts having the first element of the tags array as tutorial
D - All the posts which contains 0 or more tags named tutorial

Q 32 - Consider that the posts collection contains an array called ratings which contains
ratings given to the post by various users in the following format:

{
_id: 1,
post_text: �This is my first post�,
ratings: [5, 4, 2, 5],
//other elements of document
}

Which of the following query will return all the documents where the array ratings contains
at least one element between 3 and 6?
A - db.inventory.find( { ratings: { $elemMatch: { $gt: 3, $lt: 6 } } } )
B - db.inventory.find( { ratings: { ratings: { $gt: 5, $lt: 9 } } } )
C - db.inventory.find( { ratings: { ratings.$: { $gt: 5, $lt: 9 } } } )
D - db.inventory.find( { ratings: { $elemMatch: { $gte: 3, $lte: 6 } } } )

Q 33 - Consider that the posts collection contains an array called ratings which contains
ratings given to the post by various users in the following format:

{
_id: 1,
post_text: �This is my first post�,
ratings: [5, 4, 2, 5],
//other elements of document
}

Which of the following query will return all the documents where the ratings array contains
elements that in some combination satisfy the query conditions?
A - db.inventory.find( { ratings: { $elemMatch: { $gt: 3, $lt: 6 } } } )
B - db.inventory.find( { ratings: { ratings: { $gt: 5, $lt: 9 } } } )
C - db.inventory.find( { ratings: { ratings.$: { $gt: 5, $lt: 9 } } } )
D - db.inventory.find( { ratings: { $elemMatch: { $gte: 3, $lte: 6 } } } )

Q 34 - Which option should be used to update all the documents with the specified
condition in the MongoDB query?
A - updateAll instead of update
B - specify {multi : true} as the third parameter of update command
C - specify {all: true} as the third parameter of update command
D - specify {updateAll: true} as the third parameter of update command

Q 35 - What does the following query do when performed on the posts collection?
db.posts.update({_id:1},{Title:This is post with ID 1"})
A - Updates the Title of the post
B - Updating a document is possible only with $set
C - Replaces the complete document with _id as 1 with the document specified in second
parameter
D - Syntax error

Q 36 - What does the following query do when performed on the posts collection?
db.posts.update({_id:1},{$set:{Author:�Tom"}})
A - Sets the complete document with _id as 1 with the document specified in second parameter
by replacing it completely
B - Adds a new field Author in the searched collection if not already present
C - Updates only the Author field of the document with _id as 1
D - Both b and c

Q 37 - Which option can be used with update command so that a new document gets created
if no matching document is found based on the query condition?
A - Specify {upsert : true } as the third parameter of update command
B - upsert command instead of update command
C - {update: true, insert: true} as the third parameter of update command
D - This has to be handled in application code (Node.js, PHP, JAVA, C#, etc.) and cannot be
handled in mongo shell query

Q 38 - Consider that you are using { upsert : true } option in your update command. Which of
the following parameters will be used to determine if any new documents were inserted:
A - nMatched
B - nInserted
C - nModified
D - nUpserted

Q 39 - Which of the following commands removes a single document that matches the
condition that Author is Joe?
A - db.posts.removeOne( { Author : "Joe" }, 1 )
B - db.posts.remove( { Author : "Joe" }, 1 )
C - db.posts.remove( { Author : "Joe" }, {justOne: true} )
D - Both b and c
Q 40 - What is the output of following two commands in MongoDB:
db.posts.insert({"_id":1})
db.posts.insert({"_id":1})
A - Two documents will be inserted with _id as 1
B - MongoDB will automatically increment the _id of the second document as 2
C - This will throw a duplicate key error
D - It will insert two documents and throw a warning to the user

Q 41 - Which option should be used with findAndModify() command to return the
modified document instead of the pre-modification document?
A - findAndModify by default returns the pre-modification document
B - Set {new : true}
C - Use the POST version of findAndModify called findAndModifyPost
D - Both b and c are valid

Q 42 - Consider the following posts document:

{
_id: 1,
post_text: �This is my first post�,
author: �Tom�,
tags: [�tutorial�,�quiz�,�facebook�,�learning�,�fun�]
}

Which of the following queries will return the documents but with only the first two tags in
the tags array?
A - db.posts.find({author:"Tom"},{tags:{$slice:2}})
B - db.posts.find({author:"Tom"}).limit({tags:2})
C - db.posts.find({author:"Tom"}).limit($slice:{tags:2})
D - Both a and c are valid. $slice works both with projection and limit.

Q 43 - Which are the ONLY ways to project portions of an array?


A - $elemMatch
B - $slice
C - $
D - All of the above

Q 44 - Which of the following operator can be used to limit the number of documents in an
array field of a document after an update is performed?
A - $push along with $each, $sort and $slice
B - $removeFromSet
C - $arrayLimit
D - None of the above

Q 45 - Which of the following methods can be used on a cursor object?


A - cursor.next()
B - cursor.hasNext()
C - cursor.forEach()
D - All of the above

Q 46 - Which language is MongoDB written in?


A - C++
B - Java
C - Python
D - MongoC

Q 47 - Which type of indexes does MongoDB support?


A - Compound Indexes
B - Multikey Indexes
C - Geospatial Indexes
D - All of the above

Q 48 - What does the totalKeysExamined field returned by the explain method indicate?
A - Number of documents that match the query condition
B - Number of index entries scanned
C - Number of documents scanned
D - Details the completed execution of the winning plan as a tree of stages
Q 49 - If the value of totalKeysExamined is 30000 and the value of totalDocsExamined is 0,
which of the following option is correct?
A - The query used an index to fetch the results
B - The query returned 30000 documents after scanning the documents
C - The query returned 0 documents
D - None of the above

Q 50 - You can implement a multi-document transaction in MongoDB using which of the
following concept?
A - Tailable Cursor
B - Two Phase Commits
C - Compound Indexing
D - Multi Document Transaction is not supported by MongoDB

Q 51 - Update If Correct is an approach for which of the following concepts in MongoDB:
A - Concurrency Control
B - Transaction Management
C - Atomicity
D - Performance Management

Q 52 - Which of the following about Capped Collections is correct?


A - Fixed Size
B - If the allocated space for a capped collection exceeds, it stops inserting new documents
C - High-throughput operations that insert and retrieve documents based on insertion order
D - Only a and c

Q 53 - Which of the following is not a system collection in MongoDB?


A - database.system.indexes
B - database.system.namespaces
C - admin.system.users
D - admin.system.preferences

Q 54 - What is the equivalent command in MongoDB for the following SQL query?
SELECT * FROM posts WHERE author like "%john%"
A - db.posts.find( { author: /john/ } )
B - db.posts.find( { author: {$like: /john/} } )
C - db.posts.find( { $like: {author: /john/} } )
D - db.posts.find( { author: /^john^/ } )

Q 55 - For capped collection, cursors which do not automatically close and remain open after
the client exhausts the results are called:
A - Capped Cursors
B - Tailable Cursors
C - Open Cursors
D - Indexing Cursors

Q 56 - What is the default size of a GridFS chunk?


A - 16 MB
B - 255 K
C - 1 MB
D - 2 MB

Q 57 - Which of the following collections are used by MongoDB to store GridFS data?
A - fs.files and fs.chunks
B - fs.grid and fs.chunks
C - fs.parts and fs.files
D - fs.chunks and fs.parts

Q 58 - Which is the correct order (lowest to highest) in which MongoDB compares the BSON
types?
A - Null, Number, String and Object
B - Number, Null, String and Object
C - String, Null, Number and Object
D - Null, Number, Object and String

Q 59 - As per the aggregation pipeline optimization concepts, if you have a $sort followed
by a $match:
A - $match moves before $sort
B - $sort moves before $match
C - MongoDB does not do any movements by default and will use the order provided
D - Providing these parameters in any order does not impact the performance

Q 60 - Aggregation Pipelines have a limit of:


A - 2 MB document and 100 MB RAM
B - 16 MB document and 100 MB RAM
C - 2 MB document and no limit on RAM
D - No limit on document and 100 MB RAM

Q 61 - Which of the following methods can be used in MongoDB for relation documents?
A - Manual References
B - DBRefs
C - Both a and b
D - There is no concept of relations in documents

Q 62 - Which of the following command inside aggregate command is used in MongoDB
aggregation to filter the documents to pass only the documents that match the specified
condition(s) to the next pipeline stage.
A - $group
B - $match
C - $aggregate
D - $sum

Q 63 - What does the following aggregate query perform?

db.posts.aggregate( [
{ $match : { likes : { $gt : 100, $lte : 200 } } },
{ $group: { _id: null, count: { $sum: 1 } } }
] );

A - Calculates the number of posts with likes between 100 and 200
B - Groups the posts by number of likes (101, 102, 103�.) by adding 1 every time
C - Fetches the posts with likes between 100 and 200 and sets their _id as null
D - Fetches the posts with likes between 100 and 200, sets the _id of the first document as null
and then increments it 1 every time

Q 64 - What does the output x of the following MongoDB aggregation query result into:
db.posts.aggregate( [ { $group: { _id: "$author", x: { $sum: �$likes� } } } ] )
A - Average of likes on all the posts of an author, grouped by author
B - Number of posts by an author
C - Sum of likes on all the posts by an author, grouped by author
D - Sum of likes on all the posts by all the authors

Q 65 - Consider that you have a collection called population which has fields state and city.
Which of the following query will calculate the population grouped by state and city?
A - db.population.aggregate( [{ $group: { _id: { state: "$state", city: "$city" },pop: { $sum:
"$pop" } } }] )
B - db.population.aggregate( [{ $group: { _id: { state: "$state", city: "$city" },pop: { $sum: 1 } } }] )
C - db.population.aggregate( [{ $group: { _id: { state: "$state", city: "$city" },pop: { �$pop�: 1 } }
}] )
D - db.population.aggregate( [{ $group: { _id: { city: "$city" },pop: { $sum: "$pop" } } }] )Multi
Document Transaction is not supported by MongoDB

Q 66 - What is the minimum sensible number of voting nodes to a replica set?
A - 2
B - 3
C - 4
D - 5

Q 67 - In a sharded replica set environment, the w Option provides ability for write concern
and j Option provides ability for the data to be written on disk journal. Consider that we
have a seven member replica set and we want to assure that the writes are committed to
journal. What should be the value of j?
A - 0
B - 1
C - 2
D - 7

Q 68 - In a sharded replica set environment, the w Option provides ability for write concern
and j Option provides ability for the data to be written on disk journal. Consider that we
have a seven member replica set and we want to assure that the writes are committed to
journal as well as acknowledged by at least 3 nodes. What should be the value of w?
A - 0
B - 1
C - 3
D - 7

Q 69 - In a sharded replicas set environment with multiple mongos servers, which of the
following would decide the mongos failover?
A - mongo shell
B - mongod
C - individual language drivers
D - mongos

Q 70 - The following aggregation option is used to specify the specific fields that needs to
be passed to the next stage of the aggregation pipeline:
A - $match
B - $project
C - $group
D - $aggregate

Q 71 - Given the following posts document:

{
"_id" : 1,
"post_text" : "This post does not matter�,
�tags�: [ "tutorial", "fun", "learning"],
// rest of the document
}

What will be the output of following query:


db.posts.aggregate( [ { $unwind : "$tags" } ] )
A - Return three separate documents for three separate tags
B - Arranges the tags (wind) in ascending order
C - Arranges the tags (wind) in descending order
D - Returns one document but converts the tags array in an object

Q 72 - Which of the following command is used to get all the indexes on a collection?
A - db.collection.getIndexes()
B - db.collection.showIndexes()
C - db.collection.findIndexes()
D - db.showIndexes()

Q 73 - Given a collection posts as shown below having a document array comments, which
of the following command will create an index on the comment author descending?

{
�_id�:1,
�post_text�:�This is a sample post�,
�author�:�Tom�,
�comments�:[
{
�author�:�Joe�,
�comment_text�:�This is comment 1�
},
{
�author�:�Leo�,
�comment_text�:�This is comment 2�
}
]
}

A - db.posts.createIndex({�comments.$.author":-1});
B - db.posts.createIndex({�comments.author":-1});
C - db.posts.createIndex({�comments.author":1});
D - db.posts.createIndex({�comments.$.author": {�$desc�:1}});

Q 74 - Which of the following commands create an unique index on author field of the posts
collection?
A - db.posts.createIndex({"author":1 }, {"unique": true});
B - db.posts.createIndex({"author": unique });
C - db.posts.createIndex({"author": {�$unique�:1} });
D - db.posts.createIndexUnique({"author":1 });

Q 75 - Which of the following SQL terminology is same as $match in MongoDB?


A - WHERE
B - HAVING
C - Both WHERE and HAVING
D - GROUP BY

Q 76 - What will be the equivalent MongoDB command for the following SQL command:
SELECT author, count(*) FROM posts GROUP BY author HAVING count(*) > 1
A

db.posts.aggregate( [
{
$group: {
_id: "$author",
count: { $sum: 1 },
$match: { count: { $gt: 1 } }
}
}
])

B -
db.posts.aggregate( [
{
$group: {
_id: "$author",
count: { $sum: 1 }
}
},
{ $match: { count: { $gt: 1 } } }
])

C -

db.posts.aggregate( [
{ $match: { count: { $gt: 1 } } },
{
$group: {
_id: "$author",
count: { $sum: 1 }
}
}
])

D -

db.posts.aggregate( [
{
$group: {
_id: "$author",
count: { $sum: "$author" }
}
},
{ $match: { count: { $gt: 1 } } }
])

Q 77 - Which of the following aggregate commands in MongoDB uses a pipeline approach
with the goals of improving the aggregation performance?
A - aggregate
B - mapReduce
C - group
D - All of the above

Q 78 - Which of the following aggregation commands in MongoDB does not support
sharded collections?
A - aggregate
B - mapReduce
C - group
D - All of the above

Q 79 - What is a replica set node which does not maintain its own data but exists only for
voting purpose called?
A - Secondary
B - Arbiter
C - Delayed
D - Hidden

Q 80 - In a replica set, a ________ number of members ensures that the replica set is always
able to select a primary.
A - Odd
B - Even
C - Depends on the application architecture
D - 2

Q 81 - Which of the tags in a replica set configuration specify the operations to be read from
the node with the least network latency?
A - primaryPreferred
B - secondaryPreferred
C - nearest
D - netLatency

Q 82 - The oplog (operations log) is a special capped collection that keeps a rolling record of
all operations that modify the data stored in your databases. All the replica set members
contain a copy of the oplog in the following collection:
A - oplog.rs
B - local.oplog.rs
C - <database>..oplog.rs
D - <replicasetid>.oplog.rs
Q 83 - In a sharded replica set environment, w defines the level and kind of write concern.
Which of the following values of w specifies to return success only after a majority of
voting members have acknowledged?
A - n
B - majority
C - m
D - major

Q 84 - Which of the following is the correct syntax for starting a new mongod process and
specifying its replica set name as rs0:
A - mongod --replSet "rs0"
B - mongod --repl "rs0"
C - mongod "rs0"
D - First execute this: mongod --replSet. And then execute this: rs.add()

Q 85 - Which of the following aggregation query will sort the posts collection with author
key ascending:
A - db.posts.aggregate([ {$sort:{ author:1 } } ])
B - db.posts.aggregate([ {$sort:{ author:-1 } } ])
C - db.posts.aggregate([ {author: {$sort: 1} } ])
D - You need to first use $group or $project or $match command before $sort in the pipeline

Q 86 - The difference between $push and $addToSet is:


A - $addToSet adds the item to the field only if the new item is of the same datatype
B - $addToSet needs the fields to be already present while $push will work even if the field is
not present
C - $addToSet adds the item to the field only if it does not exist already; while $push pushes
the item to the field irrespective of whether it was present or not
D - There is no major difference between them. $addToSet is a deprecated version of $push.
Q 87 - Which format/standard is used by MongoDB internally to store documents?
A - BSON
B - JSON
C - JSON - Extended
D - B+ Trees

Q 88 - Which of the following operators can reverse the effects of a double unwind
operation?
A - $push
B - $wind
C - $wind.$wind
D - Can�t be reversed.

Q 89 - We can insert multiple documents in bulk using which of the following operations:
A - initializeUnorderedBulkOp
B - initializeBulkOp
C - initializeBulk
D - initializeUnorderedBulk

Q 90 - Consider that you have the following two documents in the products collection:
{ "_id" : 1, "prices" : [ 60, 100, 200 ] }
{ "_id" : 2, "prices" : [ 20, 90, 150 ] }
What will the following query result into:
db.products.update(
{ _id: 1, prices: 100 },
{ $set: { "prices.$" : 111 } }
)

A - Updates 60 to 100


B - Updates 100 to 111
C - Updates 60,100 and 200 to 111
D - Removes the three elements of the prices array and replaces it with only a single element
111
Q 91 - The _______ operator can be used to identify an element in the array to be updated
without explicitly specifying the position of the element.
A - $
B - $elemMatch
C - $slice
D - Updating an array field without knowing its index is not possible.

Q 92 - The ________ operator limits the contents of an array field from the query results to
contain only the first element matching the query condition.
A - $
B - $elemMatch
C - $slice
D - An array cannot be retrieved element wise in MongoDB.

Q 93 - Consider the following document from the products collection:

{
_id: 1,
product_code: "345678",
variations: [
{ size: "L", price: 1000 },
{ size: "M", price: 800 }
]
}

What does the following query using $elemMatch return?

db.products.find( { product_code: "345678" },


{ variations: { $elemMatch: { size: �L� } } } )

A - Returns the complete document since MongoDB does not support partial array retrieval
B - Returns the document but with only one element in the variations array (corresponding to
size L)
C - Returns the complete document but retrieves only the size field from the array
D - Returns the complete document but retrieves only the size field from the array and also
with only one element in the variations array (corresponding to size L)
Q 94 - What does the following $slice query return using the following command?

db.posts.find( {}, { comments: { $slice: [ -10, 5 ] } } )

A - Returns 5 comments, beginning with the last 10 items


B - Returns 10 comments, beginning with the first
C - Returns 10 comments, beginning with the last
D - Returns 5 comments, beginning with the first 10 items

Q 95 - Which of the following operator can be used to control the number of items of an
array that a query returns?
A - $
B - $elemMatch
C - $slice
D - MongoDB does not support partial retrieval of items from an array

Q 96 - When should we consider representing a one-to-many relationship in an embedded


collection instead of separate collection?
A - When the many is very large
B - When the many is not very large
C - Never
D - Always

Q 97 - Which index is used to index the content stored in arrays?


A - Multikey Index
B - Compound Index
C - Text Index
D - Sparse Index

Q 98 - Suppose that you have the following three documents in your system:
{ _id: 1, product_code: "123456", description: "mongo db tutorial" }
{ _id: 2, product_code: "345567", description: �this is mongo tutorial" }
{ _id: 3, product_code: �123431", description: "my mongo� }
If you create a text index on the description field and then apply a text search on term
�mongo�, which all documents will be fetched.
A - 1 and 2
B - 2 and 3
C - 1 and 3
D - All of the above

Q 99 - If you have created a compound index on (A,B, C) which of the following access
pattern will not be able to utilize the index?
A - A, B, C
B - A, B
C - B, C
D - A

Q 100 - Which command can be used to rebuild the indexes on a collection in MongoDB?
A - db.collection.createIndex({reIndex:1})
B - db.collection.createIndex({author:1}).reIndex()
C - db.collection.reIndex()
D - db.collection.reIndex({author:1})

S-ar putea să vă placă și