MongoDB MCQ Questions - Index
This section focuses on "Index" in MongoDB. These Multiple Choice Questions (MCQ) should be practiced to improve the MongoDB skills required for various interviews (campus interview, walk-in interview, company interview), placements, entrance exams and other competitive examinations.
1. How to create index in mongoDB?
A. index()
B. createIndex()
C. putIndex()
D. getIndex()
View Answer
Ans : B
Explanation: To create an index, you need to use createIndex() method of MongoDB.
2. Which of the following iis correct syntax of createindex?
A. db.COLLECTION_NAME.createIndex({KEY:1})
B. COLLECTION_NAME.createIndex({KEY:1})
C. db.COLLECTION_NAME.createIndex
D. db.createIndex({KEY:1})
View Answer
Ans : A
Explanation: The basic syntax of createIndex() method is as follows() : >db.COLLECTION_NAME.createIndex({KEY:1})
3. To create index in descending order, the value of key is?
A. 1
B. 0
C. -1
D. infinite
View Answer
Ans : C
Explanation: key is the name of the field on which you want to create index and 1 is for ascending order. To create index in descending order you need to use -1.
4. The default value of background Parameter is :
A. TRUE
B. FALSE
C. 0
D. 1
View Answer
Ans : B
Explanation: Builds the index in the background so that building an index does not block other database activities. Specify true to build in the background. The default value is false.
5. The default value of default_language Parameter is :
A. Mongo
B. DB
C. Mongod
D. English
View Answer
Ans : D
Explanation: For a text index, the language that determines the list of stop words and the rules for the stemmer and tokenizer. The default value is English.
6. Which method deletes multiple (specified) indexes on a collection?
A. dropIndexes()
B. dropIndex()
C. Both A and B can be used
D. getIndexes()
View Answer
Ans : A
Explanation: DropIndexs() method deletes multiple (specified) indexes on a collection while dropIndex() drop a particular index using the dropIndex() method of MongoDB.
7. Which method returns the description of all the indexes int the collection?
A. putIndexes()
B. setIndexes()
C. getIndexes()
D. All of the above
View Answer
Ans : C
Explanation: getIndexes() method returns the description of all the indexes int the collection.
8. The maximum value of weights parameter is:
A. 999
B. 9999
C. 99999
D. 99
View Answer
Ans : C
Explanation: The weight is a number ranging from 1 to 99,999 and denotes the significance of the field relative to the other indexed fields in terms of the score.
9. What is the type of sparse parameter in createIndex()?
A. Boolean
B. string
C. integer
D. document
View Answer
Ans : A
Explanation: The type of sparse parameter in createIndex() is Boolean.
10. What is the type of weights parameter in createIndex()?
A. Boolean
B. string
C. integer
D. document
View Answer
Ans : D
Explanation: The type of weights parameter in createIndex() is document.
Discussion