dropIndex
This commit is contained in:
parent
f1aa28b9e4
commit
7df946f697
1 changed files with 10 additions and 1 deletions
|
@ -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"
|
||||||
|
|
Loading…
Reference in a new issue