MongoDB DBA · 题目 283 · 单选

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:

题目选项

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

答案置信度:低

正确答案:C

解析语言:中文

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

所在套题

此题在题库中有 6 条记录。公开详情合并相同题干和选项;完整公开题展示置信度最高的一条记录,其他题目仅展示摘要。按套学习保留每条记录原有的答案、解析和置信度。

作者 · 作品 · 开源

作者与 MongoDB 作品

专注数据平台、MongoDB 迁移同步与云运维产品研发。

有任何 MongoDB 需求,均可联系作者。

联系作者 ↗mlhp123@outlook.com

支持作者

如果题库对您有帮助,欢迎自愿扫码打赏。

支付宝扫码打赏作者打开打赏原图 ↗