61. Which command creates a time-series collection?
- a) db.createCollection("logs", { timeseries: { timeField: "timestamp" } })
- b) db.createTimeseries()
- c) db.makeTimeSeries()
- d) db.collection.timeseries()
Test your knowledge of Database - [MongoDB] section with these interactive multiple-choice questions.
61. Which command creates a time-series collection?
62. What is the purpose of the $densify operator?
$densify inserts documents if values are missing in a range (e.g., timestamps).
63. Which method returns execution statistics for a query?
db.collection.find().explain("executionStats") shows performance metrics.
64. What does the $rand operator do?
{ $rand: {} } produces a pseudo-random number in aggregation.
65. Which command starts a MongoDB transaction?
const session = db.getMongo().startSession().
66. What is the purpose of the $accumulator operator?
$accumulator allows custom aggregation functions (e.g., weighted averages).
67. Which operator validates documents against a JSON Schema?
{ $jsonSchema: { ... } } enforces document structure during queries.
68. What does the $linearFill operator do?
$linearFill computes missing values between known points in time-series data.
69. Which method creates a search index?
70. What is the purpose of the $unionWith stage?
$unionWith performs a union of pipelines from different collections.
71. Which operator rounds numbers to integer?
72. What does the $getField operator do?
{ $getField: { field: "name", input: "$object" } } accesses nested fields.
73. Which command changes stream settings?
74. What is the purpose of the $tsIncrement operator?
$tsIncrement gets the increment portion of a MongoDB timestamp (for change streams).
75. Which method returns change stream events?
watch() returns a cursor for real-time data changes (inserts/updates/deletes).
76. What does the $binary operator represent?
{ $binary: "base64data", $type: "00" } stores binary payloads.
77. Which operator implements bitwise operations?
78. What is the purpose of the $meta operator?
{ $meta: "textScore" } retrieves computed values like relevance scores.
79. Which command enables client-side field-level encryption?
80. What does the $function operator allow?
$function executes custom JavaScript functions in aggregation pipelines (requires server-side scripting enabled).