From 1b0157c935a6544fa5660f2ba192f348a4bdaa12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Pila=C5=99?= Date: Mon, 16 Apr 2012 19:54:45 +0200 Subject: [PATCH 1/3] Added a new version of 'save' which returns the value of the _id field of the saved document (if it did not have _id field, it returns the generated value) --- Database/MongoDB/Query.hs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Database/MongoDB/Query.hs b/Database/MongoDB/Query.hs index 00043cc..600594e 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 From 85c3213e8a214ad734d6b95d0b2a7ee4f9f7738f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Pila=C5=99?= Date: Mon, 16 Apr 2012 19:55:25 +0200 Subject: [PATCH 2/3] Version bump. --- mongoDB.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 262ba00bdea9acb9e3acf4ef003c8b9dc6fffffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Pila=C5=99?= Date: Mon, 16 Apr 2012 20:06:28 +0200 Subject: [PATCH 3/3] Dummy commit (to attach this pull request to the issue at hand). This commit fixes #17 --- Database/MongoDB/Query.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Database/MongoDB/Query.hs b/Database/MongoDB/Query.hs index 600594e..eb5705c 100644 --- a/Database/MongoDB/Query.hs +++ b/Database/MongoDB/Query.hs @@ -313,7 +313,7 @@ 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 + Just i -> repsert (Select ["_id" := i] col) doc replace :: (MonadIO m) => Selection -> Document -> Action m () -- ^ Replace first document in selection with given document