【问题标题】:MongoDb Failing to Build Index - Caught exception during index builder initializationMongoDb 无法构建索引 - 在索引构建器初始化期间捕获异常
【发布时间】:2025-12-24 13:15:16
【问题描述】:

当我尝试在我的 Atlas 服务器上构建复合索引时,它没有显示任何错误,但随后没有构建索引。

通过shell尝试,我得到以下信息:

MongoDB Enterprise mongos> db.myCollection.createIndex( {"user_id": "hashed", "identifier": 1, "timestamp": 1} )
{
    "raw" : {
        "atlas-lgwyih-shard-1/atlas-lgwyih-shard-01-00.kqohn.mongodb.net:27017,atlas-lgwyih-shard-01-01.kqohn.mongodb.net:27017,atlas-lgwyih-shard-01-02.kqohn.mongodb.net:27017" : {
            "ok" : 0,
            "errmsg" : "Caught exception during index builder initialization my-db.myCollection (c22f2095-1221-43cd-80af-13f2fb3afaff): 1 provided. First index spec: { ns: \"my-db.myCollection\", v: 2, key: { user_id: \"hashed\", identifier: 1.0, timestamp: 1.0 }, name: \"user_id_hashed_identifier_1_timestamp_1\" }",
            "code" : 16763,
            "codeName" : "Location16763"
        }
    },
    "code" : 16763,
    "codeName" : "Location16763",
    "ok" : 0,
    "errmsg" : "Caught exception during index builder initialization my-db.myCollection (c22f2095-1221-43cd-80af-13f2fb3afaff): 1 provided. First index spec: { ns: \"my-db.myCollection\", v: 2, key: { user_id: \"hashed\", identifier: 1.0, timestamp: 1.0 }, name: \"user_id_hashed_identifier_1_timestamp_1\" }",
    "operationTime" : Timestamp(1596400670, 1),
    "$clusterTime" : {
        "clusterTime" : Timestamp(1596400671, 4),
        "signature" : {
            "hash" : BinData(0,"oh8t17bzKDwsyxv4WzK5suDFP9U="),
            "keyId" : NumberLong("6855996587379516447")
        }
    }
}

到目前为止,我在集合上只有默认索引:

MongoDB Enterprise mongos> db.getCollection("myCollection").getIndexes()
[
    {
        "v" : 2,
        "key" : {
            "_id" : 1
        },
        "name" : "_id_",
        "ns" : "my-db.myCollection"
    }
]

请注意,我希望此索引按此顺序排列,因为我想使用散列用户 ID 上的分片键对集合进行分片。

是什么导致了这个错误?

【问题讨论】:

    标签: database mongodb indexing


    【解决方案1】:

    啊,由于某种原因,经过数小时的头撞墙后,我只是想确认是否可以使用一种类型的哈希创建复合索引。事实证明这是导致错误的原因——希望错误信息更清楚!

    此外,正如下面的 cmets 所指出的,现在 4.4 版支持此功能!

    【讨论】:

    • 这在4.4服务器中支持,但在以前的版本中不支持。