I have a structure like this:
type Document struct {
ID primitive.ObjectID `bson:"_id,omitempty"`
description string `bson:"description,omitempty"`
}
And I have the getter for description field:
func (d *Document) Description() string {
strip := bluemonday.StripTagsPolicy()
return strip.Sanitize(d.description)
}
But when I try to save the document to the MongoDb it ignores description field:
func (d *Document) SaveMongo() (*mongo.InsertOneResult, error) {
insertResult, err := App.MongoCollection.InsertOne(context.Background(), d)
...
}
How can I save private field using getter?