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 -- * Index
Key, Unique, Key, Unique,
Direction(..), Direction(..),
createIndex, createIndex, dropIndex,
) )
where where
import Control.Exception import Control.Exception
@ -645,6 +645,15 @@ createIndex c col keys uniq = do
("unique", toBson uniq)] ("unique", toBson uniq)]
return name 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 :: [(Key, Direction)] -> String
indexName = List.concat . List.intersperse "_" . fmap partName indexName = List.concat . List.intersperse "_" . fmap partName
where partName (k, Ascending) = k ++ "_1" where partName (k, Ascending) = k ++ "_1"