How to set a primary key in MongoDB?

前端 未结 9 996
再見小時候
再見小時候 2020-12-07 21:46

I want to set one of my fields as primary key. I am using MongoDB as my NoSQL.

9条回答
  •  难免孤独
    2020-12-07 22:39

    _id field is reserved for primary key in mongodb, and that should be a unique value. If you don't set anything to _id it will automatically fill it with "MongoDB Id Object". But you can put any unique info into that field.

    Additional info: http://www.mongodb.org/display/DOCS/BSON

    Hope it helps.

提交回复
热议问题