dropIndex

This commit is contained in:
Scott R. Parish 2010-01-19 22:44:14 -06:00
parent f1aa28b9e4
commit 7df946f697

View file

@ -48,7 +48,7 @@ module Database.MongoDB
-- * Index
Key, Unique,
Direction(..),
createIndex,
createIndex, dropIndex,
)
where
import Control.Exception
@ -645,6 +645,15 @@ createIndex c col keys uniq = do
("unique", toBson uniq)]
return name
-- | Drop the specified index on the given /FullCollection/.
dropIndex :: Connection -> FullCollection -> [(Key, Direction)] -> IO ()
dropIndex c col keys = do
let (db, col') = splitFullCol col
name = indexName keys
_ <- runCommand c db $ toBsonDoc [("deleteIndexes", toBson col'),
("index", toBson name)]
return ()
indexName :: [(Key, Direction)] -> String
indexName = List.concat . List.intersperse "_" . fmap partName
where partName (k, Ascending) = k ++ "_1"