How should one work with indices?

Hi @TopherGopher,

Sorry, this got lost in my inbox. mongo.IndexModel is a helper type used to store information when creating indices, not a type to unpack index specifications into. Driver version 1.5.0 will include an IndexView.ListSpecifications function that calls listIndexes and unpacks all results into a helper type rather than simply returning a Cursor object. In the meantime, you can see the struct definition for this type and copy it into your code:

type IndexSpecification struct {
// copied from Go Driver
}

cursor, err := coll.Indexes().List(nil)
is.NoError(err)
var indices []IndexSpecification
is.NoError(cursor.All(nil, &indices))
is.GreaterOrEqual(len(indicies), 9)
2 Likes