mongodb / mongo-php-driver

The Official MongoDB PHP driver
https://pecl.php.net/package/mongodb
Apache License 2.0
889 stars 204 forks source link

Command exceptions don't contain full command result #296

Closed alcaeus closed 6 years ago

alcaeus commented 8 years ago

Some commands return additional information when encountering an error. In this specific case, the shardCollection command contains a list of indexes and a proposed key in its result if the shard key is not already present as an index:

mongos> db.adminCommand({shardCollection: 'doctrine_odm_tests.sharded.one', key: { k: 1 }})
{
    "proposedKey" : {
        "k" : 1
    },
    "curIndexes" : [
        {
            "v" : 1,
            "key" : {
                "_id" : 1
            },
            "name" : "_id_",
            "ns" : "doctrine_odm_tests.sharded.one"
        }
    ],
    "ok" : 0,
    "errmsg" : "please create an index that starts with the shard key before sharding."
}

However, when running this command through the driver, the resulting MongoDB\Driver\Exception\RuntimeException does not contain the proposedKey and curIndexes fields. This makes it impossible to use the command result to get the proper index one should create for the shard key.

jmikola commented 7 years ago

It looks like we'll get this functionality in a future version of libmongoc (CDRIVER-1110). Our tracking ticket is: PHPC-578.

alcaeus commented 6 years ago

I noticed this has been fixed in libmongoc 1.7.0 - any chance we'll see it in one of the next driver releases?

Doctrine MongoDB ODM relies on this feature when enabling sharding. The code could be refactored to add the shard key as regular index if it doesn't exist yet, but I thought it was better to rely on the server to let us know of a recommended index for the shard key.

jmikola commented 6 years ago

I'll discuss this with @derickr tomorrow during our ticket triage. :+1:

jmikola commented 6 years ago

Closing this out. Please follow PHPC-578 for updates, as we've scheduled that for the forthcoming 1.5.0 release.