0

I have a collection and I set shard it. I have errors while I add a shard key!!!

mongos> sh.shardCollection('IBSng.connection_log', {login_time:1})

But I was shown this error: Even I set compound shard with logout_time field with login_time, But the result shown to me this error.

{
    "proposedKey" : {
        "login_time" : 1
    },
    "curIndexes" : [
        {
            "v" : 1,
            "key" : {
                "_id" : 1
            },
            "name" : "_id_",
            "ns" : "IBSng.connection_log"
        },
        {
            "v" : 1,
            "key" : {
                "user_id" : 1
            },
            "name" : "user_id_1",
            "ns" : "IBSng.connection_log"
        },
        {
            "v" : 1,
            "key" : {
                "ras_id" : 1
            },
            "name" : "ras_id_1",
            "ns" : "IBSng.connection_log"
        },
        {
            "v" : 1,
            "key" : {
                "retry_count" : 1
            },
            "name" : "retry_count_1",
            "ns" : "IBSng.connection_log"
        },
        {
            "v" : 1,
            "key" : {
                "credit_used" : 1
            },
            "name" : "credit_used_1",
            "ns" : "IBSng.connection_log"
        },
        {
            "v" : 1,
            "key" : {
                "details.mac" : 1
            },
            "name" : "details.mac_1",
            "ns" : "IBSng.connection_log"
        },
        {
            "v" : 1,
            "key" : {
                "username" : 1
            },
            "name" : "username_1",
            "ns" : "IBSng.connection_log"
        },
        {
            "v" : 1,
            "key" : {
                "type_details.in_bytes" : 1,
                "type_details.out_bytes" : 1
            },
            "name" : "type_details.in_bytes_1_type_details.out_bytes_1",
            "ns" : "IBSng.connection_log"
        },
        {
            "v" : 1,
            "key" : {
                "details.kill_reason" : 1
            },
            "name" : "details.kill_reason_1",
            "ns" : "IBSng.connection_log"
        },
        {
            "v" : 1,
            "key" : {
                "details.terminate_cause" : 1
            },
            "name" : "details.terminate_cause_1",
            "ns" : "IBSng.connection_log"
        },
        {
            "v" : 1,
            "key" : {
                "login_time" : -1,
                "logout_time" : -1
            },
            "name" : "login_time_-1_logout_time_-1",
            "ns" : "IBSng.connection_log",
            "sparse" : false
        }
    ],
    "ok" : 0,
    "errmsg" : "please create an index that starts with the shard key before sharding."
}

I Waiting for your answers.

Makoto
  • 765
  • 2
  • 17
  • 45
user255327
  • 47
  • 1
  • 6

1 Answers1

0

Add an index for {login_time:1}, this is different to that compound one you have done.

Wizard
  • 4,341
  • 1
  • 15
  • 13