Discussion:
can't shard collection with unique index?
gen liu
2011-11-02 02:43:30 UTC
Permalink
I have a collection with a unique index:{{"folder":1,"name":
1},unique:true},
Then I try to shard the collection:

db.runCommand( { shardcollection : "test.content", key: { _id: 1}} )
it reports error:"can't shard collection with unique index".
I know i can remove the unique index from the collection, and choose
the shard key as unique, like:
db.runCommand( { shardcollection : "test.content", key: { folder: 1,
name: 1}, unique: true} )

But the new shard key ( {folder:1,name:1} ) is not a good key for me.
Any advice?
Nat
2011-11-02 03:04:02 UTC
Permalink
It's a limitation since if your unique index is not a shard key, the uniqueness is not guaranteed since the same key can appear on different shards.
-----Original Message-----
From: gen liu <tomliugen-***@public.gmane.org>
Sender: mongodb-user-/***@public.gmane.org
Date: Tue, 1 Nov 2011 19:43:30
To: mongodb-user<mongodb-user-/***@public.gmane.org>
Reply-To: mongodb-user-/***@public.gmane.org
Subject: [mongodb-user] can't shard collection with unique index?

I have a collection with a unique index:{{"folder":1,"name":
1},unique:true},
Then I try to shard the collection:

db.runCommand( { shardcollection : "test.content", key: { _id: 1}} )
it reports error:"can't shard collection with unique index".
I know i can remove the unique index from the collection, and choose
the shard key as unique, like:
db.runCommand( { shardcollection : "test.content", key: { folder: 1,
name: 1}, unique: true} )

But the new shard key ( {folder:1,name:1} ) is not a good key for me.
Any advice?
--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongodb-user-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to mongodb-user+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
Loading...