How do you implement an auto-incrementing primary ID in MongoDB?

后端 未结 7 1595
伪装坚强ぢ
伪装坚强ぢ 2020-12-05 12:11

Just like in MYSQL, I want an incrementing ID.

7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-05 12:44

    @TIMEX : Check if below link can help you, if you were looking for a sequence number not ID (coz ID is reserved by mongo)

    http://docs.mongodb.org/manual/tutorial/create-an-auto-incrementing-field/#auto-increment-counters-collection

    @Dennis Burton Auto increment if user does will it not cause collision? i feel, hence mongo db uses its own _Id so it can avoid collision, but if user wishes to have a column as a running sequence they are free to have it

提交回复
热议问题