Kamva / mgm

Mongo Go Models (mgm) is a fast and simple MongoDB ODM for Go (based on official Mongo Go Driver)
Apache License 2.0
754 stars 63 forks source link

feat: support customizing model PK #42

Closed WenyXu closed 3 years ago

WenyXu commented 3 years ago

support customizing model PK

mehran-prs commented 3 years ago

Hi @WenyXu Thanks for your PR, but in MongoDB, you can't change the primary key's name.

_id is a special field in MongoDB. It's a unique identifier for each doc and there is no way you can have a document without it. Even if you are trying to insert the document without it, mongo will create it for you on each document, you can not even modify the _id field. but you can change its type(e.g., insert as a string instead of ObjectID).