From 90877190879cb08958f210a9274f420f71121151 Mon Sep 17 00:00:00 2001 From: Ralph Morton Date: Fri, 19 Jun 2015 18:26:38 +0200 Subject: [PATCH] Support for TTL --- Database/MongoDB/Admin.hs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Database/MongoDB/Admin.hs b/Database/MongoDB/Admin.hs index 8aaacaf..09fbcb0 100644 --- a/Database/MongoDB/Admin.hs +++ b/Database/MongoDB/Admin.hs @@ -34,6 +34,7 @@ import Control.Applicative ((<$>)) import Control.Concurrent (forkIO, threadDelay) import Control.Monad (forever, unless, liftM) import Data.IORef (IORef, newIORef, readIORef, writeIORef) +import Data.Maybe (maybeToList) import Data.Set (Set) import System.IO.Unsafe (unsafePerformIO) @@ -98,7 +99,8 @@ data Index = Index { iKey :: Order, iName :: IndexName, iUnique :: Bool, - iDropDups :: Bool + iDropDups :: Bool, + iExpireAfterSeconds :: Maybe Int } deriving (Show, Eq) idxDocument :: Index -> Database -> Document @@ -107,11 +109,11 @@ idxDocument Index{..} db = [ "key" =: iKey, "name" =: iName, "unique" =: iUnique, - "dropDups" =: iDropDups ] + "dropDups" =: iDropDups ] ++ (maybeToList $ fmap ((=:) "expireAfterSeconds") iExpireAfterSeconds) index :: Collection -> Order -> Index -- ^ Spec of index of ordered keys on collection. Name is generated from keys. Unique and dropDups are False. -index coll keys = Index coll keys (genName keys) False False +index coll keys = Index coll keys (genName keys) False False Nothing genName :: Order -> IndexName genName keys = T.intercalate "_" (map f keys) where