Hello Stefano,
Consider the following documents, which will have separate, unique
index entries in the compound index, {user: 1, email: 1}:
{user: "Jenna", email: "y"}
{user: "Jenna", email: "x"}
A compound index cannot be used to maintain uniqueness on two distinct
fields; it can only be used to ensure uniqueness for the combination
of values. Dropping the uniqueness on a single field and maintaining
uniqueness programmatically is workaround for this situation.
On Oct 4, 10:57 am, stefanoric <
stefano.riccia...@gmail.com> wrote:
> Hi,
>
> I have a collection of "users" with 2 unique indexes (username and email).
>
> I tried sharding this collection on username, but mongo complains about not
> being able to maintain uniqueness.
>
> I think I understand why I said that (might end up with two users with the
> same email in 2 different shards), so I tried to sharding using *both *username
> *and *email as shard key, but still mongo complains.