Alex Rivera | Logout

How to set a primary key in MongoDB?

Asked 2010-07-21T12:04:30.860
115

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

Edit
Report

1 Answer

120

_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.

answered 2010-07-21T12:11:40.723

Your Answer