MongoDB and composite primary keys

前端 未结 4 1631
温柔的废话
温柔的废话 2020-12-07 21:55

I\'m trying to determine the best way to deal with a composite primary key in a mongo db. The main key for interacting with the data in this system is made up of 2 uuids. Th

4条回答
  •  太阳男子
    2020-12-07 22:55

    I'd go for the 2 option and there is why

    1. Having two separate fields instead of the one concatenated from both uuids as suggested in 1st, will leave you the flexibility to create other combinations of indexes to support the future query requests or if turns out, that the cardinality of one key is higher then another.
    2. having non sequential keys could help you to avoid the hotspots while inserting in sharded environment, so its not such a bad option. Sharding is the best way, for my opinion, to scale inserts and updates on the collections, since the write locking is on database level (prior to 2.6) or collection level (2.6 version)

提交回复
热议问题