MongoDB DBA · Question 283 · Single choice

1Consider a collection called reviews which consists of documents with the following fields: product_name (string) this field is not unique as there are several products with the same prefix product_id (ObjectId) this field has several duplicates as popular products get more reviews review (string) almost unique across all documents, only a few duplicate values reviewer_id (string) this field has a few values that are in many document for frequent reviewers, these are the exception as most people only give a few reviews rating (integer) this field contains a value from 1 to 5 reviewed_at (Timestamp) almost unique across all documents, only a few duplicate values _id (ObjectId) automatically created on insert, unique across all documents Which of the following shard keys below is the best of those listed to support queries on the reviews collection? Choose the best answer:

Answer options

  1. A.
    { product_id: 1, _id: 1}
  2. B.
    { reviewed_at: 1, product_name: 1}
  3. C.
    { reviewer_id: 1, reviewed_at: 1}

Answer confidence: Low

Correct answer: C

Explanation language: Chinese

这道题的考生答案存在分歧(DBA 卷记 {reviewed_at, product_name}、DEV 卷记 {reviewer_id, reviewed_at}),我按分片键三要素判定:reviewer_id 大多数情况下取值不重复(只有少数高频评论者是例外),基数高、频率低且不是单调递增,再加 reviewed_at 作后缀打破重复,整体最均衡,故取 C。B 的致命点是 reviewed_at 为单调递增的时间戳,新评论会持续落到最后一个 chunk 形成写热点;A 的 product_id 对热门商品频率极高,容易产生无法分裂的 jumbo chunk。

Papers containing this question

This question appears in 6 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 ↗