Skip to content

Commit

Permalink
new: add method to delete indexes (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-serafin authored and primalmotion committed Apr 17, 2019
1 parent 2eda7e7 commit 184d789
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions manipmongo/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,28 @@ func CreateIndex(manipulator manipulate.Manipulator, identity elemental.Identity
return nil
}

// DeleteIndex deletes multiple mgo.Index for the collection.
func DeleteIndex(manipulator manipulate.Manipulator, identity elemental.Identity, indexes ...string) error {

m, ok := manipulator.(*mongoManipulator)
if !ok {
panic("you can only pass a mongo manipulator to DeleteIndex")
}

session := m.rootSession.Copy()
defer session.Close()

collection := session.DB(m.dbName).C(identity.Name)

for _, index := range indexes {
if err := collection.DropIndexName(index); err != nil {
return err
}
}

return nil
}

// CreateCollection creates a collection using the given mgo.CollectionInfo.
func CreateCollection(manipulator manipulate.Manipulator, identity elemental.Identity, info *mgo.CollectionInfo) error {

Expand Down

0 comments on commit 184d789

Please sign in to comment.