I am watching a tutorial on how to create Go restful APIs that use MongoDB for persistence (this one to be more precise).
The instructor is using in his model (struct) both json
and bson
tags, something like
type NoteUpdate struct {
ID string `json:"id,omitempty" bson:"_id,omitempty"`
Title string `json:"title" bson:"title,omitempty"`
Content string `json:"content" bson:"content,omitempty"`
ChangedAt int64 `json:"changed_at" bson:"changed_at"`
}
However the official go driver example does not do so.
As a matter of fact there, no struct tags are used at all.
What is the purpose / usefulness of using bson
tags?
The one thing that comes to my mind is the case were one would want to create custom mongo _id
fields in which case an explicit bson
mapping with that struct's field should be declared.
Is there any other added value for the bson
tags?