How to generate unique object id in mongodb

前端 未结 3 710
醉话见心
醉话见心 2020-12-05 23:29

When I use Mongodb with Java, I want to generate Object id at clients. Before I insert a record, however, I have to query mongodb first to make sure that the id generated by

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-05 23:54

    Object IDs are not like sequential ids you use in a RDMS. If they are properly generated according to the Object ID specification you will not need to worry about them being unique.

    All you have to do is ensure you always create a new Object ID rather than reusing them.

提交回复
热议问题