41. Which command lists all indexes in a collection?
- a) db.collection.getIndexes()
- b) db.collection.listIndexes()
- c) db.collection.indexes()
- d) Both A and B
getIndexes() and listIndexes() display collection indexes.
Test your knowledge of Database - [MongoDB] section with these interactive multiple-choice questions.
41. Which command lists all indexes in a collection?
getIndexes() and listIndexes() display collection indexes.
42. What is the purpose of the $merge stage in aggregation?
$merge writes aggregation results to a collection with options like merging or replacing.
43. Which operator checks array size in MongoDB?
{ field: { $size: 3 } } matches arrays with exactly 3 elements.
44. What does the $natural sort do?
.sort({ $natural: 1 }) returns documents in native storage order.
45. Which method is used for bulk write operations?
bulkWrite() performs multiple insert/update/delete operations in bulk.
46. What is the purpose of the $expr operator?
$expr enables aggregation expressions like $eq within regular queries.
47. Which command repairs a MongoDB database?
48. What does the $convert operator do?
$convert: { input: "123", to: "int" } converts values between types.
49. Which operator performs a case-insensitive regex search?
{ field: { $regex: /pattern/i } } enables case-insensitive matching.
50. What is the purpose of the $facet stage?
$facet runs multiple aggregation pipelines within one stage.
51. Which method returns distinct field values?
db.collection.distinct("field") returns unique values.
52. What does the $geoNear operator do?
$geoNear sorts documents by distance from a point (requires geospatial index).
53. Which command flushes pending writes to disk?
fsyncLock() locks writes and flushes data to disk (for backups).
54. What is the purpose of the $dateToString operator?
{ $dateToString: { format: "%Y-%m-%d", date: "$field" } }.
55. Which operator checks if a field is an array?
{ field: { $type: "array" } } to check array type.
56. What does the $binarySize operator return?
{ $binarySize: "$binField" } returns the byte length.
57. Which method creates a capped collection?
58. What is the purpose of the $indexOfBytes operator?
{ $indexOfBytes: [ "$str", "sub" ] } finds substring position.
59. Which command lists all running operations?
currentOp() displays active operations in the database.
60. What does the $toUpper operator do?
{ $toUpper: "$field" } transforms text to uppercase.