Godeps/_workspace/src/gopkg.in/mgo.v2/session.go
func (c *Collection) Indexes() (indexes []Index, err error) {
	// Clone session and set it to Monotonic mode so that the server
	// used for the query may be safely obtained afterwards, if
	// necessary for iteration when a cursor is received.
	session := c.Database.Session
	cloned := session.Clone()
	cloned.SetMode(Monotonic, false)
	defer cloned.Close()

	batchSize := int(cloned.queryConfig.op.limit)

	// Try with a command.
	var result struct {
		Indexes []bson.Raw

		Cursor struct {
			FirstBatch []bson.Raw "firstBatch"
			NS         string
			Id         int64
		}
	}
	var iter *Iter
	err = c.Database.With(cloned).Run(bson.D{{"listIndexes", c.Name}, {"cursor", bson.D{{"batchSize", batchSize}}}}, &result)
	if err == nil {
		firstBatch := result.Indexes
		if firstBatch == nil {
			firstBatch = result.Cursor.FirstBatch
		}
		ns := strings.SplitN(result.Cursor.NS, ".", 2)
		if len(ns) < 2 {
			iter = c.With(cloned).NewIter(nil, firstBatch, result.Cursor.Id, nil)
		} else {
			iter = cloned.DB(ns[0]).C(ns[1]).NewIter(nil, firstBatch, result.Cursor.Id, nil)
		}
	} else if isNoCmd(err) {
		// Command not yet supported. Query the database instead.
		iter = c.Database.C("system.indexes").Find(bson.M{"ns": c.FullName}).Iter()
	} else {
		return nil, err
	}

	var spec indexSpec
	for iter.Next(&spec) {
		indexes = append(indexes, indexFromSpec(spec))
	}
	if err = iter.Close(); err != nil {
		return nil, err
	}
	sort.Sort(indexSlice(indexes))
	return indexes, nil
}
func (c *Collection) Indexes() (indexes []Index, err error) {
	// Clone session and set it to Monotonic mode so that the server
	// used for the query may be safely obtained afterwards, if
	// necessary for iteration when a cursor is received.
	session := c.Database.Session
	cloned := session.Clone()
	cloned.SetMode(Monotonic, false)
	defer cloned.Close()

	batchSize := int(cloned.queryConfig.op.limit)

	// Try with a command.
	var result struct {
		Indexes []bson.Raw

		Cursor struct {
			FirstBatch []bson.Raw "firstBatch"
			NS         string
			Id         int64
		}
	}
	var iter *Iter
	err = c.Database.With(cloned).Run(bson.D{{"listIndexes", c.Name}, {"cursor", bson.D{{"batchSize", batchSize}}}}, &result)
	if err == nil {
		firstBatch := result.Indexes
		if firstBatch == nil {
			firstBatch = result.Cursor.FirstBatch
		}
		ns := strings.SplitN(result.Cursor.NS, ".", 2)
		if len(ns) < 2 {
			iter = c.With(cloned).NewIter(nil, firstBatch, result.Cursor.Id, nil)
		} else {
			iter = cloned.DB(ns[0]).C(ns[1]).NewIter(nil, firstBatch, result.Cursor.Id, nil)
		}
	} else if isNoCmd(err) {
		// Command not yet supported. Query the database instead.
		iter = c.Database.C("system.indexes").Find(bson.M{"ns": c.FullName}).Iter()
	} else {
		return nil, err
	}

	var spec indexSpec
	for iter.Next(&spec) {
		indexes = append(indexes, indexFromSpec(spec))
	}
	if err = iter.Close(); err != nil {
		return nil, err
	}
	sort.Sort(indexSlice(indexes))
	return indexes, nil
}
func ( c * Collection ) Indexes ( ) ( indexes [ ] Index , err error ) { // Clone session and set it to Monotonic mode so that the server // used for the query may be safely obtained afterwards, if // necessary for iteration when a cursor is received. session := c . Database . Session cloned := session . Clone ( ) cloned . SetMode ( Monotonic , false ) defer cloned . Close ( ) batchSize := int ( cloned . queryConfig . op . limit ) // Try with a command. var result struct { Indexes [ ] bson . Raw Cursor struct { FirstBatch [ ] bson . Raw " " NS string Id int64 } } var iter * Iter err = c . Database . With ( cloned ) . Run ( bson . D { { " " , c . Name } , { " " , bson . D { { " " , batchSize } } } } , & result ) if err == nil { firstBatch := result . Indexes if firstBatch == nil { firstBatch = result . Cursor . FirstBatch } ns := strings . SplitN ( result . Cursor . NS , " " , 2 ) if len ( ns ) < 2 { iter = c . With ( cloned ) . NewIter ( nil , firstBatch , result . Cursor . Id , nil ) } else { iter = cloned . DB ( ns [ 0 ] ) . C ( ns [ 1 ] ) . NewIter ( nil , firstBatch , result . Cursor . Id , nil ) } } else if isNoCmd ( err ) { // Command not yet supported. Query the database instead. iter = c . Database . C ( " " ) . Find ( bson . M { " " : c . FullName } ) . Iter ( ) } else { return nil , err } var spec indexSpec for iter . Next ( & spec ) { indexes = append ( indexes , indexFromSpec ( spec ) ) } if err = iter . Close ( ) ; err != nil { return nil , err } sort . Sort ( indexSlice ( indexes ) ) return indexes , nil }
// Indexes returns a list of all indexes for the collection.
//
// For example, this snippet would drop all available indexes:
//
//   indexes, err := collection.Indexes()
//   if err != nil {
//       return err
//   }
//   for _, index := range indexes {
//       err = collection.DropIndex(index.Key...)
//       if err != nil {
//           return err
//       }
//   }
//
// See the EnsureIndex method for more details on indexes.
Indexes returns a list of all indexes for the collection . For example this snippet would drop all available indexes : indexes err : = collection . Indexes () if err ! = nil { return err } for _ index : = range indexes { err = collection . DropIndex ( index . Key ... ) if err ! = nil { return err } } See the EnsureIndex method for more details on indexes .