Unable to create index while sharding
When i am trying to enable the shard... I am getting following errors........
use admin
switched to db admin
> db.runCommand( { enablesharding : "sgserver" } )
{ "ok" : 1 }
> db.runCommand( { shardcollection : "sgserver.block_seek_pos", key : {fileGUID : 1} } )
"ok" : 0,
"errmsg" : "please create an index over the sharding key before sharding."
> db.sgserver.ensureIndex({"fileGUID": 1})
> db.runCommand( { shardcollection : "sgserver.block_seek_pos", key : {fileGUID : 1} } )
"ok" : 0,
"errmsg" : 开发者_如何学Python"please create an index over the sharding key before sharding."
Its insisting that I create an index, but if I try to create an index I am getting the above mentioned error.
Can anyone help me out with this?
Is the sgserver
collection inside of the admin
database?
I don't see the command where you switch to the correct database before you do ensureIndex()
. The code should probably look like this:
db.runCommand( { enablesharding : "sgserver" } );
use sgserver;
db.sgserver.ensureIndex({"fileGUID": 1});
db.runCommand( { shardcollection : "sgserver.block_seek_pos", key : {fileGUID : 1} } )
精彩评论