func ensureIndexes() { ses := mongo.GetSession() defer ses.Close() index := mgo.Index{ Key: []string{"public_id"}, Unique: false, } mongo.GetCollection(ses, session.Collection).EnsureIndex(index) }
// createCollection creates a collection in the new database. func createCollection(ses *mgo.Session, db *DB, col *Collection, dropIdxs bool) error { if mongo.CollectionExists("", ses, col.Name) { return ErrCollectionExists } mCol := mongo.GetCollection(ses, col.Name) if err := mCol.Create(new(mgo.CollectionInfo)); err != nil { return err } if err := createIndexes(ses, mCol, col, dropIdxs); err != nil { return err } return nil }