Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

_________ specifies a polygon for a geospatial $geoWithin query on legacy coordinate pairs.(a) $rect(b) $polygon(c) $poly(d) All of the mentionedThis question was posed to me in final exam.Asked question is from Indexing Methods in chapter Index/Indexing Concepts of MongoDB

Answer»

The correct answer is (B) $POLYGON

For explanation: To define the polygon, specify an array of coordinate POINTS.

2.

Only the ______ geospatial index supports the $polygon operator.(a) 1dsphere(b) 2d(c) 3d(d) None of the mentionedThe question was posed to me during an internship interview.The above asked question is from Indexing Methods in chapter Index/Indexing Concepts of MongoDB

Answer»

Right ANSWER is (b) 2d

Best explanation: The $polygon operator calculates distances using FLAT (PLANAR) GEOMETRY.

3.

Applications can use _________ without having a geospatial index.(a) $center(b) $centre(c) $radii(d) $centersphereI have been asked this question in an international level competition.This key question is from Indexing Methods topic in portion Index/Indexing Concepts of MongoDB

Answer»

Correct CHOICE is (d) $centersphere

The best I can explain: The QUERY RETURNS documents that are within the bounds of the CIRCLE.

4.

Point out the correct statement.(a) Applications can use $center without having a geospatial index(b) Before 3.0, a geospatial index must exist on a field holding coordinates before using any of the geospatial query operators(c) To use $centerSphere, specify an array that contains grid coordinates of the circle’s center point(d) None of the mentionedI got this question during an interview.Origin of the question is Indexing Methods topic in portion Index/Indexing Concepts of MongoDB

Answer» RIGHT option is (a) Applications can use $CENTER without having a GEOSPATIAL index

The explanation is: However, geospatial indexes support much FASTER queries than the unindexed EQUIVALENTS.
5.

When used with the $box operator, _________ returns documents based on grid coordinates and does not query for GeoJSON shapes.(a) $geoNear(b) $geoWithin(c) $geoRear(d) All of the mentionedThe question was posed to me by my college director while I was bunking the class.The doubt is from Indexing Methods topic in portion Index/Indexing Concepts of MongoDB

Answer»

The correct CHOICE is (B) $geoWithin

The EXPLANATION is: To use the $box operator, you must specify the bottom left and TOP right corners of the rectangle in an ARRAY object.

6.

_________ defines a circle for a geospatial query that uses spherical geometry.(a) $center(b) $centre(c) $radii(d) $centersphereThis question was posed to me during an online interview.My query is from Indexing Methods topic in portion Index/Indexing Concepts of MongoDB

Answer»

Right option is (d) $centersphere

The BEST explanation: You can use the $centerSphere operator on both GEOJSON objects and LEGACY COORDINATE PAIRS.

7.

Point out the wrong statement.(a) The query scans the index and not the collection(b) If overall selectivity is high, and if MongoDB must read a number of documents to return results, then some queries may perform faster without indexes(c) A better strategy, depending on your queries, would be to create a compound index that includes the high-selectivity field and another field(d) None of the mentionedI got this question in my homework.This question is from Indexing Methods in chapter Index/Indexing Concepts of MongoDB

Answer»

Right answer is (b) If overall selectivity is high, and if MongoDB must READ a number of documents to return results, then some queries may perform FASTER without indexes

To EXPLAIN I would say: To ensure selectivity, write queries that limit the number of POSSIBLE documents with the INDEXED field. Write queries that are appropriately selective relative to your indexed data.

8.

__________ query calculates distances using flat (planar) geometry.(a) $center(b) $centre(c) $radii(d) SortI have been asked this question in an interview for internship.This is a very interesting question from Indexing Methods in chapter Index/Indexing Concepts of MongoDB

Answer»

The correct answer is (a) $center

For EXPLANATION: In MongoDB, sort operations can obtain the sort ORDER by retrieving DOCUMENTS BASED on the ORDERING in an index.

9.

Indexes do not have to fit entirely into ______ in all cases.(a) ROM(b) RAM(c) Secondary Storage(d) None of the mentionedThe question was asked in semester exam.Enquiry is from Indexing Strategies in chapter Index/Indexing Concepts of MongoDB

Answer»

The correct CHOICE is (a) ROM

To EXPLAIN: There are some limited CASES where indexes do not NEED to fit in MEMORY.

10.

__________ method provides a wrapper around the totalIndexSize output of the collStats (i.e. db.collection.stats()) operation.(a) db.collection.totalallIndexSize()(b) db.collection.totalIndexSizeAll()(c) db.collection.totalIndexSize()(d) all of the mentionedI got this question in homework.Asked question is from Indexing Strategies in section Index/Indexing Concepts of MongoDB

Answer» RIGHT choice is (c) db.collection.totalIndexSize()

The best explanation: To check the SIZE of your INDEXES, use the db.collection.totalIndexSize() helper, which returns data in BYTES.
11.

An index can support sort operations on a non-prefix subset of the index key pattern using _________ condition.(a) predicate(b) selection(c) equality(d) none of the mentionedThis question was addressed to me during an interview.My query is from Indexing Strategies topic in chapter Index/Indexing Concepts of MongoDB

Answer» CORRECT ANSWER is (c) equality

Best explanation: Query MUST include equality conditions on all the prefix keys that precede the SORT keys.
12.

Sort operations that do not use an index will abort when they use _______ megabytes of memory.(a) 16(b) 32(c) 64(d) All of the mentionedI had been asked this question by my college professor while I was bunking the class.This question is from Indexing Strategies topic in division Index/Indexing Concepts of MongoDB

Answer»

The CORRECT CHOICE is (b) 32

The EXPLANATION is: If the query planner cannot OBTAIN the SORT order from an index, it will sort the results in memory.

13.

Point out the correct statement.(a) If you only ever query on a single key in a given collection, then you need to create just multikey index for that collection(b) If you sometimes query on only one key and at other times query on that key combined with a second key, then creating a compound index is more efficient than creating a single-key index(c) The choice between creating compound indexes that support your queries or relying on index intersection is independent of specifics of your system(d) None of the mentionedI had been asked this question in an internship interview.My enquiry is from Indexing Strategies topic in division Index/Indexing Concepts of MongoDB

Answer»

The CORRECT answer is (B) If you sometimes query on only ONE KEY and at other times query on that key combined with a second key, then creating a compound index is more efficient than creating a single-key index

For EXPLANATION: MongoDB will use the compound index for both queries.

14.

A prefix of a _______ index is a subset that consists of one or more keys at the start of the index key pattern.(a) unique(b) primary(c) compound(d) none of the mentionedI have been asked this question in unit test.Enquiry is from Indexing Strategies in portion Index/Indexing Concepts of MongoDB

Answer» RIGHT choice is (B) primary

The explanation is: If the SORT keys correspond to the index keys or an index PREFIX, MongoDB can use the index to sort the QUERY results.
15.

_________ operations that use an index often have better performance than those that do not use an index.(a) Select(b) Update(c) Delete(d) SortI got this question by my school principal while I was bunking the class.My question comes from Indexing Strategies topic in chapter Index/Indexing Concepts of MongoDB

Answer»

The correct option is (d) Sort

Easy explanation: In MongoDB, sort OPERATIONS can OBTAIN the sort order by RETRIEVING DOCUMENTS based on the ordering in an index.

16.

Point out the wrong statement.(a) The query scans the index and the collection(b) An index supports a query when the index contains all the fields scanned by the query(c) Creating indexes that support queries results in greatly increased query performance(d) None of the mentionedThis question was addressed to me during a job interview.This intriguing question comes from Indexing Strategies topic in section Index/Indexing Concepts of MongoDB

Answer» RIGHT ANSWER is (a) The QUERY scans the index and the collection

Best EXPLANATION: The query scans the index and not the collection.
17.

The default weight is ____ for the indexed fields.(a) 1(b) 2(c) 3(d) 4The question was asked in unit test.My question is based upon Text Search in division Index/Indexing Concepts of MongoDB

Answer»

The correct option is (a) 1

Easiest EXPLANATION: To ADJUST the WEIGHTS for the indexed fields, include the weights option in the db.collection.createIndex() METHOD.

18.

To avoid creating an index with a name that exceeds the index name length limit, you can pass the _____ option to the db.collection.createIndex() method.(a) name(b) lang(c) number(d) all of the mentionedThis question was posed to me in exam.I'm obligated to ask this question of Text Search in chapter Index/Indexing Concepts of MongoDB

Answer»

Correct option is (a) name

The EXPLANATION is: The measuring units for the MAXIMUM distance are determined by the COORDINATE system in use.

19.

Point out the correct statement.(a) After 2.4, you can terminate both background index builds and foreground index builds(b) The specified language in the document overrides the default language for the text index(c) The text index, like other indexes, should not fall within the index name length limit(d) None of the mentionedI had been asked this question in homework.I want to ask this question from Text Search in portion Index/Indexing Concepts of MongoDB

Answer» RIGHT answer is (b) The specified LANGUAGE in the document overrides the default language for the text index

Explanation: To GET the names of the indexes, USE the db.collection.getIndexes() method.
20.

The default name for the index consists of each indexed field name concatenated with _______(a) _char(b) _textc(c) _text(d) All of the mentionedThe question was asked in a job interview.Asked question is from Text Search in portion Index/Indexing Concepts of MongoDB

Answer»

The CORRECT answer is (c) _text

The explanation is: WHETHER the TEXT index has the default name or you SPECIFIED a name for the text index, to drop the text index, pass the index name to the db.collection.dropIndex() method.

21.

To use a field with a name other than language, include the ________ option when creating the index.(a) language_over(b) language_override(c) langoverride(d) none of the mentionedThis question was addressed to me in a job interview.This question is from Text Search in portion Index/Indexing Concepts of MongoDB

Answer»

The CORRECT ANSWER is (B) language_override

Easiest explanation: You cannot combine the $text query, which requires a special text INDEX, with a query operator that requires a different type of special index.

22.

If a collection contains documents or embedded documents that are in different languages, include a field named _______ in the documents.(a) operator(b) lang(c) language(d) all of the mentionedI got this question in class test.I would like to ask this question from Text Search in portion Index/Indexing Concepts of MongoDB

Answer»

The correct option is (B) lang

To EXPLAIN: MongoDB will use the specified language for that DOCUMENT or embedded document when building the TEXT index.

23.

The default language for the indexed data is ________(a) chinese(b) english(c) spanish(d) none of the mentionedI had been asked this question during an interview for a job.My question is based upon Text Search in section Index/Indexing Concepts of MongoDB

Answer»

The correct option is (b) english

Explanation: To specify a DIFFERENT language, USE the default_language option when creating the TEXT INDEX.

24.

Point out the wrong statement.(a) In order to drop a text index, use the index name(b) The default language associated with the indexed data determines the rules to parse word roots and ignore stop words(c) To allow for text search on all fields with string content, use the wildcard specifier ($$$) to index all fields that contain string content(d) None of the mentionedThe question was posed to me in exam.The question is from Text Search in section Index/Indexing Concepts of MongoDB

Answer»

Correct option is (c) To ALLOW for text search on all fields with string content, use the WILDCARD specifier ($$$) to index all fields that contain string content

Explanation: In the aggregation PIPELINE, text search is available via the use of the $text query OPERATOR in the $match stage.

25.

When creating a text index on multiple fields, you can specify the individual fields or you can use wildcard specifier ______(a) ($*)(b) (**$**)(c) ($**)(d) None of the mentionedThis question was addressed to me in unit test.This interesting question is from Text Search in division Index/Indexing Concepts of MongoDB

Answer»

The correct answer is (C) ($**)

The best I can explain: You can create a text index on the FIELD or FIELDS WHOSE VALUE is a string or an array of string elements.

26.

The _________ operator specifies a circle for a $geoWithin query.(a) $within(b) $gwithin(c) $center(d) All of the mentionedThis question was posed to me in an interview for internship.My question is from Geospatial Index topic in chapter Index/Indexing Concepts of MongoDB

Answer»

The CORRECT option is (c) $center

To elaborate: The QUERY returns legacy coordinate PAIRS that are WITHIN the BOUNDS of the circle.

27.

__________ specifies a minimum distance to limit the results of $near and $nearSphere queries.(a) $center(b) $maxDistance(c) $minDistance(d) All of the mentionedI had been asked this question by my college director while I was bunking the class.My enquiry is from Geospatial Index in chapter Index/Indexing Concepts of MongoDB

Answer»

Correct ANSWER is (C) $minDistance

Easiest EXPLANATION: $minDistance is available for USE with 2dsphere INDEX only.

28.

_________ returns geospatial objects in proximity to a point on a sphere. Requires a geospatial index.(a) $near(b) $nearsphere(c) $geoIntersect(d) None of the mentionedThe question was posed to me in an international level competition.My doubt stems from Geospatial Index topic in section Index/Indexing Concepts of MongoDB

Answer»

The CORRECT ANSWER is (B) $nearsphere

Best explanation: The 2dsphere and 2D indexes support $nearSphere.

29.

Point out the correct statement.(a) Both 2dsphere and 2d geospatial indexes support $geoWithin(b) $geoWithin does not require a geospatial index(c) The $geoWithin operator does not return sorted results(d) None of the mentionedThis question was posed to me during an interview.My question comes from Geospatial Index topic in chapter Index/Indexing Concepts of MongoDB

Answer»

The CORRECT ANSWER is (b) $geoWithin does not require a geospatial index

For explanation I would SAY: HOWEVER, a geospatial index will improve query PERFORMANCE.

30.

_________ specifies a geometry in GeoJSON format to geospatial query operators.(a) $sphere(b) $geoin(c) $geometry(d) All of the mentionedI had been asked this question during an online interview.My enquiry is from Geospatial Index topic in division Index/Indexing Concepts of MongoDB

Answer»

The correct option is (C) $GEOMETRY

The explanation: $geometry uses EPSG:4326 as the default COORDINATE REFERENCE system (CRS).

31.

_______ returns geospatial objects in proximity to a point.(a) $near(b) $nearsphere(c) $geoIntersect(d) None of the mentionedThis question was addressed to me during an online interview.My question comes from Geospatial Index topic in section Index/Indexing Concepts of MongoDB

Answer»

The correct ANSWER is (a) $NEAR

For explanation I WOULD SAY: $near requires a geospatial index.

32.

Point out the wrong statement.(a) If $near or $nearSphere query specifies the center point as a GeoJSON point, specify the distance as a non-negative number in meters(b) If $nearSphere query specifies the center point as legacy coordinate pair, specify the distance as a non-negative number in radians(c) $near can only use the 2dsphere index if the query specifies the center point as a GeoJSON point(d) None of the mentionedI had been asked this question in a national level competition.The query is from Geospatial Index topic in section Index/Indexing Concepts of MongoDB

Answer» CORRECT CHOICE is (d) None of the mentioned

To explain: $minDistance filters the results of a geospatial $near or $nearSphere query to those documents that are at least the specified distance from the center POINT.
33.

___________ selects geometries that intersect with a GeoJSON geometry.(a) $near(b) $nearsphere(c) $geoIntersect(d) None of the mentionedI had been asked this question in homework.This interesting question is from Geospatial Index in chapter Index/Indexing Concepts of MongoDB

Answer»

The CORRECT ANSWER is (C) $geoIntersect

Explanation: The 2dsphere INDEX SUPPORTS $geoIntersects.

34.

The __________ operator constrains the results of a geospatial $near or $nearSphere query to the specified distance.(a) $center(b) $maxDistance(c) $minDistance(d) all of the mentionedThe question was asked in an interview for job.Asked question is from Index Management topic in chapter Index/Indexing Concepts of MongoDB

Answer»

Correct CHOICE is (B) $maxDistance

To explain: The measuring units for the MAXIMUM distance are DETERMINED by the coordinate system in USE.

35.

To force MongoDB to use a particular index for a db.collection.________ operation, specify the index with the hint() method.(a) query()(b) find()(c) index()(d) all of the mentionedI had been asked this question in exam.Question is from Index Management in section Index/Indexing Concepts of MongoDB

Answer» CORRECT CHOICE is (b) find()

EXPLANATION: Append the HINT() method to the find() method.
36.

__________ views partial execution statistics collected during plan selection.(a) curs.explain()(b) cursor.explain()(c) cursr.explain()(d) all of the mentionedThe question was asked in examination.Query is from Index Management in portion Index/Indexing Concepts of MongoDB

Answer» CORRECT answer is (B) cursor.explain()

The BEST EXPLANATION: Run db.collection.explain() or the cursor.explain() METHOD in allPlansExecution mode.
37.

In the mongo shell, you can use the ______ method to return a list of the indexes on a collection.(a) getallIndexes()(b) getretIndexes()(c) getIndexes()(d) none of the mentionedI had been asked this question in semester exam.I would like to ask this question from Index Management in section Index/Indexing Concepts of MongoDB

Answer» CORRECT answer is (c) GETINDEXES()

To EXPLAIN: When performing maintenance you may WANT to check which indexes EXIST on a collection.
38.

Point out the correct statement.(a) After 4.0, you cannot terminate both background index builds and foreground index builds(b) Before MongoDB 2.1, you could only terminate background index builds(c) After 2.4, you can terminate both background index builds and foreground index builds(d) None of the mentionedI had been asked this question in an interview for internship.The origin of the question is Index Management in chapter Index/Indexing Concepts of MongoDB

Answer»

The correct CHOICE is (c) After 2.4, you can TERMINATE both background index BUILDS and foreground index builds

Easiest explanation: You cannot terminate a REPLICATED index BUILD on secondary members of a replica set.

39.

To terminate an ongoing index build, use the __________ method in the mongo shell.(a) db.currentOp()(b) db.killOp()(c) db.removeOp()(d) all of the mentionedThis question was posed to me in final exam.My doubt is from Index Management in section Index/Indexing Concepts of MongoDB

Answer» CORRECT choice is (b) db.killOp()

The explanation is: For INDEX builds, the EFFECTS of db.killOp() may not be immediate and may occur well after much of the index build operation has COMPLETED.
40.

If you need to rebuild indexes for a collection you can use the _________ method to rebuild all indexes on a collection in a single operation.(a) db.collection.Index()(b) db.collection.reIndex()(c) db.collection.rebuildIndex()(d) none of the mentionedI had been asked this question during a job interview.My enquiry is from Index Management topic in chapter Index/Indexing Concepts of MongoDB

Answer»

Correct option is (a) db.collection.Index()

EASIEST explanation: This OPERATION DROPS all indexes, INCLUDING the _id index, and then rebuilds all indexes.

41.

Point out the wrong statement.(a) To modify an existing index, you need to drop and recreate the index(b) Your client library may have a different or additional interface for this operation(c) To see the status of an indexing process, you can use the db.statusOp() method in the mongo shell(d) None of the mentionedThis question was addressed to me in exam.This intriguing question comes from Index Management in division Index/Indexing Concepts of MongoDB

Answer»

The correct choice is (C) To SEE the STATUS of an indexing process, you can use the db.statusOp() METHOD in the mongo shell

For explanation: To see the status of an indexing process, you can use the db.currentOp() method in the mongo shell.

42.

To modify an existing index, you cannot just re-issue the _________ method with the updated specification of the index.(a) dropIndex()(b) modIndex()(c) createIndex()(d) none of the mentionedThis question was posed to me in homework.Query is from Index Management in chapter Index/Indexing Concepts of MongoDB

Answer» RIGHT ANSWER is (C) createIndex()

To elaborate: To modify the index, you must drop the index first.
43.

On replica sets, the TTL background thread only deletes documents on _____________(a) primary(b) secondary(c) upadte(d) none of the mentionedThis question was addressed to me in a job interview.My question is from Index Properties in section Index/Indexing Concepts of MongoDB

Answer»

Right option is (a) PRIMARY

To ELABORATE: Secondary MEMBERS replicate DELETION OPERATIONS from the primary.

44.

You may not specify a unique constraint on a ______ index.(a) Hashed(b) Unique(c) Sparse(d) CompoundI have been asked this question by my college director while I was bunking the class.The origin of the question is Index Properties topic in portion Index/Indexing Concepts of MongoDB

Answer»

The CORRECT option is (a) Hashed

The EXPLANATION is: Because of the UNIQUE constraint, MongoDB will only PERMIT ONE document that lacks the indexed field.

45.

You can combine the ________ constraint with the sparse index to filter these null values from the unique index and avoid the error.(a) Hashed(b) Unique(c) Sparse(d) CompoundI had been asked this question in a job interview.My query is from Index Properties in chapter Index/Indexing Concepts of MongoDB

Answer»

Correct option is (c) Sparse

To EXPLAIN I would say: If a document does not have a value for the INDEXED field in a unique index, the index will STORE a NULL value for this document.

46.

Point out the wrong statement.(a) The unique constraint applies to separate documents in the collection(b) Unique index prevents separate documents from having the same value for the indexed key(c) Index does prevent a document from having multiple elements or embedded documents in an indexed array from having the same value(d) None of the mentionedThe question was asked in quiz.I would like to ask this question from Index Properties topic in portion Index/Indexing Concepts of MongoDB

Answer»

The correct ANSWER is (c) INDEX does prevent a document from having multiple elements or embedded documents in an INDEXED array from having the same value

Best explanation: In the case of a SINGLE document with repeating values, the repeated value is INSERTED into the index only once.

47.

The background task that removes expired documents runs every ________ seconds.(a) 15(b) 45(c) 60(d) 120This question was posed to me in quiz.This key question is from Index Properties topic in section Index/Indexing Concepts of MongoDB

Answer»

The correct answer is (C) 60

For EXPLANATION: As a result, documents may remain in a COLLECTION during the period between the expiration of the document and the running of the BACKGROUND task.

48.

Point out the correct statement.(a) If you build a TTL index in the foreground, MongoDB does not remove expired documents as soon as the index finishes building(b) The TTL index does guarantee that expired data will be deleted immediately upon expiration(c) Duration of the removal operation depends on the workload of your mongod instance(d) None of the mentionedThe question was asked in quiz.The question is from Index Properties in section Index/Indexing Concepts of MongoDB

Answer»

Correct option is (c) Duration of the removal OPERATION depends on the workload of your mongod instance

The BEST I can EXPLAIN: There MAY be a DELAY between the time a document expires and the time that MongoDB removes the document from the database.

49.

When the TTL thread is active, you will see _______ operations in the output of db.currentOp().(a) delete(b) update(c) insert(d) none of the mentionedI have been asked this question in final exam.I would like to ask this question from Index Properties topic in division Index/Indexing Concepts of MongoDB

Answer»

Right answer is (a) delete

For explanation I WOULD say: A BACKGROUND THREAD in mongod reads the values in the index and removes EXPIRED documents from the collection.

50.

________ indexes expire documents after the specified number of seconds has passed since the indexed field value.(a) Hashed(b) Unique(c) Multikey(d) TTLThis question was posed to me in examination.Asked question is from Index Properties topic in section Index/Indexing Concepts of MongoDB

Answer»

The correct CHOICE is (d) TTL

To explain: The expiration threshold is the indexed FIELD VALUE PLUS the SPECIFIED number of seconds.