Sunday, 15 May 2011

primary key - In MongoDB, how likely is it two documents in different collections in the same database will have the same Id? -



primary key - In MongoDB, how likely is it two documents in different collections in the same database will have the same Id? -

according mongodb documentation, _id field (if not specified) automatically assigned 12 byte objectid.

it says unique index created on field on creation of collection, want know how 2 documents in different collections still in same database instance have same id, if can happen?

i want application able retrieve document using _id field without knowing collection in, if cannot guarantee uniqueness based on way mongodb generates one, may need different way of generating id's.

short reply question : yes that's possible.

below post on similar topic helps in understanding better:

possibility of duplicate mongo objectid's beingness generated in 2 different collections?

mongodb primary-key uniqueidentifier

No comments:

Post a Comment