1

When I try to build a compound index on my Atlas server, it shows no error but then the index doesn't get built.

Trying it via shell, I get the following:

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")
        }
    }
}

I only have the default index on the collection so far:

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

Note that I want this index in this order because I want to shard the collection with the shard key being on hashed User IDs.

What is causing this error?

1 Answer 1

3

Ah, for some reason after hours of banging my head against the wall I just thought to confirm whether it's possible to create a compound index with one type being hashed. Turns out this is causing the error -- wish that error message was clearer on that!

Also, this is now supported in version 4.4 as pointed out in the comments below!

Sign up to request clarification or add additional context in comments.

1 Comment

This is supported in 4.4 server but not in previous versions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.