Context
In implementing a variant of DropIndex that gets keys rather than name from GODRIVER-2701, to match the specifications (
https://github.com/mongodb/specifications/blob/master/source/index-management/index-management.md#standard-api) the DropIndex was attempted to be implemented with generics to accurately represent a single drop function with different parameters based on whether a user wanted to drop the index with a name or key (because Go doesn't allow for same named functions without different receivers). Because Go Generics aren't allowed in v1, the implementation of using Go Generics is proposed for potentially a later version of the Go Driver.
Definition of done
Investigate whether or not we should edit the drop index function to take in either the name or key parameter as a form of input to drop an index by using Generics, and if so, perform the operation. Explore potential other Generics implementations as well.
For example, a potential non-generic implementation:
func (iv IndexView) DropOne(ctx context.Context, searchParam interface{}, opts ...*options.DropIndexesOptions) (bson.Raw, error) { if name, stringCheck := searchParam.(string); stringCheck { if name == "*" { return nil, ErrMultipleIndexDrop } return iv.drop(ctx, name, opts...) } else if key, keyCheck := searchParam.(bsoncore.Document); keyCheck { return iv.dropFromKeys(ctx, key, opts...) } return nil, ErrInvalidSearchParam }
Pitfalls
There could potentially be user-errors of inputs at runtime rather than at compilation when using generics.