diff --git a/Database/MongoDB/Query.hs b/Database/MongoDB/Query.hs index 00043cc..eb5705c 100644 --- a/Database/MongoDB/Query.hs +++ b/Database/MongoDB/Query.hs @@ -303,11 +303,17 @@ assignId doc = if X.any (("_id" ==) . label) doc -- ** Update -save :: (MonadIO' m) => Collection -> Document -> Action m () +save :: (MonadIO' m) => Collection -> Document -> Action m Value -- ^ Save document to collection, meaning insert it if its new (has no \"_id\" field) or update it if its not new (has \"_id\" field) save col doc = case look "_id" doc of - Nothing -> insert_ col doc - Just i -> repsert (Select ["_id" := i] col) doc + Nothing -> insert col doc + Just i -> repsert (Select ["_id" := i] col) doc >> return i + +save_ :: (MonadIO' m) => Collection -> Document -> Action m () +-- ^ Save document to collection, meaning insert it if its new (has no \"_id\" field) or update it if its not new (has \"_id\" field) +save_ col doc = case look "_id" doc of + Nothing -> insert_ col doc + Just i -> repsert (Select ["_id" := i] col) doc replace :: (MonadIO m) => Selection -> Document -> Action m () -- ^ Replace first document in selection with given document diff --git a/mongoDB.cabal b/mongoDB.cabal index eefc7d2..1e50aaf 100644 --- a/mongoDB.cabal +++ b/mongoDB.cabal @@ -1,5 +1,5 @@ name: mongoDB -version: 1.2.0 +version: 1.2.1 build-type: Simple license: OtherLicense license-file: LICENSE