【问题标题】:Creating an index on a large embedded array in mongo在 mongo 中的大型嵌入式数组上创建索引
【发布时间】:2020-02-28 09:20:31
【问题描述】:

我有一个包含嵌入式数组的文档。数组只是一堆字符串。我最近遇到了一些性能问题,所以我决定创建一个索引。但它不允许我这样做,因为“键太大而无法索引”。

我正在使用 AWS DocumentDB。

示例文档如下所示:

{
  _id: (mongoID),
  id: (uuid),
  employees: [(uuid of another user), ...]
}

我看到了Cannot create index in mongodb, "key too large to index" 的问题,但我并没有真正看到解决方案如何适用于我的问题。

【问题讨论】:

  • 您能否提供一个示例文档和索引规范。
  • 您使用哪个 MongoDB 版本?在最新版本中应该删除限制,请参阅Index Key Limit
  • @WernfriedDomscheit 正如我在问题中所写,我正在使用 AWS DocumentDB。还添加了一个示例文档。
  • @Valijon 我看到了那个答案,但没有看到它如何应用于我的具体问题。

标签: mongodb aws-documentdb aws-documentdb-mongoapi


【解决方案1】:

我们刚刚更新了此功能,您现在可以在大于 2048 字节的数组上创建索引,并在同一数组中创建具有多个键的复合多键索引。

https://aws.amazon.com/about-aws/whats-new/2020/04/amazon-documentdb-adds-improved-multi-key-indexing-capabilities/

【讨论】:

    【解决方案2】:

    数组索引

    Amazon DocumentDB 将数组索引为单个条目。当前无法索引大于 2048 字节的数组。

    https://docs.aws.amazon.com/documentdb/latest/developerguide/functional-differences.html#functional-differences.array-indexing

    如果employees 多于56 entries,则无法创建索引

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-25
    • 1970-01-01
    • 2015-10-13
    • 1970-01-01
    • 2021-05-13
    • 2015-11-10
    • 2021-03-14
    相关资源
    最近更新 更多