MongoDB does not support creating new unique indexes in sharded clusters and will not allow you to shard collections with unique indexes on fields other than the _id field.
I'm not sure I understand your questions but you seem to be misinterpreting some things you see.
Inline:
On Aug 17, 2014 9:51 AM, "Ted Chyn" <ted....@gmail.com> wrote:
>
> From mongodb manual, are following statements are true ? Please comments if I am in erros.
>
> 1. If a automatically generated mongo _id unique ID index. I cannot created a unique shard index(?) but this shard index{x:1} still can be use to enforce that no 2 documents can have the shard key ? (True or False)
I don't understand the question at all. Every collection must have unique index on _id and mongo enforces that. You can shard on x but index x:1 can be unique or it can be non-unique, either is allowed.
> 2. use above scenario, _id index is created as unique index and shard index is another field x. here are some thing I observed
You don't create _id index, its always there and always unique.
You didn't specify if x:1 is a unique index.
> a. if doc {x:1} already exists, shard index will prevent another doc {x:1} to be inserted.
Untrue.
Only true if x:1 is unique index.
> however, when I can insert doc (x:1, y:2} with no issue.
> is this normal ?
Since above statement was incorrect, this isn't "normal" or "not normal" - without unique index on x you can insert as many documents with same x value as you want.
> b. I did not see last error message when duplicate doc {x:1} is inserted even insertion did not occur on the database.
> is the normal ?
Insertion occurred. If it didn't then you would have seen an error message.
It looks like you replied to a rather old messages - it's better to start a new thread and include exact part of the docs that you find unclear.
The following discussion is about unique indexes on sharded collections when these indexes are NOT the shard key.
> The unique constraint on indexes ensures that only one document can have a value for a field in a collection. For sharded collections these unique indexes cannot enforce uniqueness because insert and indexing operations are local to each shard.
> --
> You received this message because you are subscribed to the Google Groups "mongodb-user"
> group.
>
> For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
> ---
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
> To post to this group, send email to mongod...@googlegroups.com.
> Visit this group at http://groups.google.com/group/mongodb-user.
> To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/7d146878-fb9f-415d-886b-487e62ce435e%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.