Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new: add method to delete indexes #65

Merged
merged 5 commits into from
Apr 17, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions manipmongo/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,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