func CheckIndex(c *mgo.Collection, key []string, unique bool) error { originIndexs, err := c.Indexes() if err != nil { return fmt.Errorf("<CheckIndex> get indexes: %v", err) } for _, index := range originIndexs { if checkIndexKey(index.Key, key) && unique == index.Unique { return nil } } return fmt.Errorf("<CheckIndex> not found index: %v unique: %v", key, unique) }