A map inside a struct is not zeroed on decoding.
For example, given this type:
type CollectionInfo struct { Name string `bson:"name"` Type string `bson:"type"` Options bson.M `bson:"options"` }
and this code:
info := &CollectionInfo{} for iter.Next(nil) { _ = iter.Decode(info) }
The bson.M fields of the struct will not be zeroed and will accumulate data as the iterator progresses. This may surprise users who expect the struct. (In this case, the correct approach is to allocate a fresh struct inside the loop.)
This should be documented. Another option might be to add a struct tag to request that a map field be zeroed.