func EnsureIndex(manipulator manipulate.Manipulator, identity elemental.Identity, indexes ...mgo.Index) error {
	m, ok := manipulator.(*mongoManipulator)
	if !ok {
		panic("you can only pass a mongo manipulator to CreateIndex")
	}
	session := m.rootSession.Copy()
	session.SetMode(mgo.Strong, false)
	session.EnsureSafe(&mgo.Safe{})
	defer session.Close()
	collection := session.DB(m.dbName).C(identity.Name)
	for i, index := range indexes {
		if index.Name == "" {
			index.Name = "index_" + identity.Name + "_" + strconv.Itoa(i)
		}
		if err := collection.EnsureIndex(index); err != nil {
			if strings.Contains(err.Error(), "already exists with different options") {
				if index.ExpireAfter > 0 {
					if err := collection.Database.Run(bson.D{
						{Name: "collMod", Value: collection.Name},
						{Name: "index", Value: bson.M{"name": index.Name, "expireAfterSeconds": int(index.ExpireAfter.Seconds())}},
					}, nil); err != nil {
						return fmt.Errorf("cannot update TTL index: %s", err)
					}
				} else {
					if err := collection.DropIndexName(index.Name); err != nil {
						return fmt.Errorf("cannot delete previous index: %s", err)
					}
					if err := collection.EnsureIndex(index); err != nil {
						return fmt.Errorf("unable to ensure index after dropping old one '%s': %s", index.Name, err)
					}
				}
				continue
			}
			return fmt.Errorf("unable to ensure index '%s': %s", index.Name, err)
		}
	}
	return nil
}
EnsureIndex works like create index, but it will delete existing index
if they changed before creating a new one.
package manipmongo
import (
	"fmt"
	"strconv"
	"strings"
	"time"
	"github.com/globalsign/mgo"
	"github.com/globalsign/mgo/bson"
	"go.aporeto.io/elemental"
	"go.aporeto.io/manipulate"
	"go.aporeto.io/manipulate/internal/backoff"
)
func DoesDatabaseExist(manipulator manipulate.Manipulator) (bool, error) {
	m, ok := manipulator.(*mongoManipulator)
	if !ok {
		panic("you can only pass a mongo manipulator to DoesDatabaseExist")
	}
	dbs, err := m.rootSession.DatabaseNames()
	if err != nil {
		return false, err
	}
	for _, db := range dbs {
		if db == m.dbName {
			return true, nil
		}
	}
	return false, nil
}
func DropDatabase(manipulator manipulate.Manipulator) error {
	m, ok := manipulator.(*mongoManipulator)
	if !ok {
		panic("you can only pass a mongo manipulator to DropDatabase")
	}
	session := m.rootSession.Copy()
	defer session.Close()
	return session.DB(m.dbName).DropDatabase()
}
func CreateIndex(manipulator manipulate.Manipulator, identity elemental.Identity, indexes ...mgo.Index) error {
	m, ok := manipulator.(*mongoManipulator)
	if !ok {
		panic("you can only pass a mongo manipulator to CreateIndex")
	}
	session := m.rootSession.Copy()
	defer session.Close()
	collection := session.DB(m.dbName).C(identity.Name)
	for i, index := range indexes {
		if index.Name == "" {
			index.Name = "index_" + identity.Name + "_" + strconv.Itoa(i)
		}
		if err := collection.EnsureIndex(index); err != nil {
			return fmt.Errorf("unable to ensure index '%s': %s", index.Name, err)
		}
	}
	return nil
}