💻 Tech
If you’re using the mongo-driver/mongo package, and you want to automatically create the _id
value with InsertOne
, you need to ensure that:
- Your struct has a property for
_id
with type of pointer to the ObjectID like so:ID *primitive.ObjectID `bson:"_id,omitempty"
- You don’t populate
_id
with a value.
If your _id
is not using pointer semantics, you will have zeroes as the value.