How to add auto increment to existing collection in mongodb/node.js?

后端 未结 2 773
鱼传尺愫
鱼传尺愫 2021-01-29 10:24

Is there any methods or packages, that can help me add auto increments to existing collection? Internet full of information, about how to add AI before you create collection, bu

2条回答
  •  一整个雨季
    2021-01-29 10:54

    MongoDB reserves the _id field in the top level of all documents as a primary key. _id must be unique, and always has an index with a unique constraint. It is an auto-incrementing field. However, it is possible to define your own auto-incrementing field following the tutorial in the MongoDB documentation.

    Tutorial link: https://docs.mongodb.com/v3.0/tutorial/create-an-auto-incrementing-field/

提交回复
热议问题