3

I am considering using UUIDs v1 for my document indexes instead of ObjectId. I am concerned about the performance and unsure of the best way to proceed with switching to uuids.

My performance concern stems from comments about ObjectID being more efficient with b-tree/indexing. What kind of performance issues am I looking at?

My other concern is the unique factor. I am creating an API to store publicly accessible documents and will eventually have to consider sharding. And there is this document from Mongo about issues with ObjectIDs uniqueness and sharding.

I am not fully clear on what issues might arise from this ability to check uniqueness across shards and if it would create problems for my situation. (basically people can create documents from the website or API and search them the same way. I would say lets think in the low millions of documents for the sake of this question. I am more concerned about fetches then lots of parallels inserts).

It seems there are pros and cons to both types of IDs. Can someone clarify this?

Mithun Satheesh
  • 27,240
  • 14
  • 77
  • 101
cyberwombat
  • 38,105
  • 35
  • 175
  • 251
  • Can you please explain more clearly why do you think that using UUIDs versus ObjectIDs will give you some reasonable performance gain? Where did you got it? – Salvador Dali Oct 13 '14 at 09:06
  • 1
    The document you link to actually recommends using ObjectIDs as a unique identifier. The _id field has a unique index by default, and ObjectIDs are the default content for _id, so I don't see where your concern about uniqueness comes from. There are other issues related to using an ObjectID as a shard key (it is monotonically increasing over time) but uniqueness is not generally a concern. I'll also point you here: http://docs.mongodb.org/manual/core/document/#the-id-field which discusses how best to store UUIDs (as BinData) and finally, why not simply have a separate UUID field and _id? – Adam Comerford Oct 13 '14 at 09:35
  • Possible duplicate of [Using UUIDs instead of ObjectIDs in MongoDB](http://stackoverflow.com/questions/28895067/using-uuids-instead-of-objectids-in-mongodb) – Maks3w Feb 05 '16 at 09:50

0 Answers0