MongoDB DBA · Question 166 · Single choice

50. Your company is planning to deploy 500 million internet connected temperature sensors that will write their data once a day into a new document. These writes account for only 10% of envisioned workload, the other 90% will be read operations analyzing the incoming data. The reads are expected to break down as follows: 60% will read documents for a given device for the last week 20% will read documents for all devices for the last month 15% will read documents where the sensors reported an error in the last day 5% will read documents where temperatures exceeded a certain temperature Here is an example of a document for a device that also reported an error code with its daily data: { "_id:": ObjectId("5c33f89a0a96f53fc48aef25"), "device_id": 184835, "time": ISODate("2019-01-08T01:11:53.681Z"), "temp": 22.5, "counter": 34544, "errors": [ 101 ] } Pick the best shard key out of the following choices: Choose the best answer:

Answer options

  1. A.
    { "counter": 1 }
  2. B.
    { "time": -1, "device_id": 1 }
  3. C.
    { "device_id": 1, "time": 1 }
  4. D.
    { "_id": 1 }
  5. E.
    { "time": 1, "device_id": 1 }

Answer confidence: High

Correct answer: C

Explanation language: Chinese

{device_id:1, time:1} 把同一设备的数据聚在同一个分片,正好支撑占比最大的“某设备最近一周”范围查询(可定向到单个分片),且 device_id 基数极高不易产生巨型 chunk。B、E 把 time 放在首位会让按时间的查询广播到所有分片并形成写入热点;A 的 counter 与查询模式无关;D 的 _id 无法被业务查询利用。

Papers containing this question

This question appears in 3 bank records. Public pages combine identical prompts and options. Selected questions display the highest-confidence record; the others show a short preview. Paper-based learning preserves each record's answer, explanation, and confidence.

AUTHOR · PROJECTS · OPEN SOURCE

Author & MongoDB projects

Building data platforms, MongoDB migration and sync tools, and cloud operations products.

Contact the author for any MongoDB needs.

Contact the author ↗mlhp123@outlook.com

Support the author

If this question bank helps you, optional donations are welcome.

Scan with Alipay to support the authorOpen full-size donation image ↗