diff --git a/Database/MongoDB/Query.hs b/Database/MongoDB/Query.hs index bbcf31a..4d2366e 100644 --- a/Database/MongoDB/Query.hs +++ b/Database/MongoDB/Query.hs @@ -21,7 +21,7 @@ module Database.MongoDB.Query ( -- ** Insert insert, insert_, insertMany, insertMany_, insertAll, insertAll_, -- ** Update - save, replace, repsert, Modifier, modify, + save, replace, repsert, upsert, Modifier, modify, -- ** Delete delete, deleteOne, -- * Read @@ -305,10 +305,10 @@ assignId doc = if any (("_id" ==) . label) doc -- ** Update 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 document to collection, meaning insert it if its new (has no \"_id\" field) or upsert 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 -> upsert (Select ["_id" := i] col) doc replace :: (MonadIO m) => Selection -> Document -> Action m () -- ^ Replace first document in selection with given document @@ -317,6 +317,11 @@ replace = update [] repsert :: (MonadIO m) => Selection -> Document -> Action m () -- ^ Replace first document in selection with given document, or insert document if selection is empty repsert = update [Upsert] +{-# DEPRECATED repsert "use upsert instead" #-} + +upsert :: (MonadIO m) => Selection -> Document -> Action m () +-- ^ Update first document in selection with given document, or insert document if selection is empty +upsert = update [Upsert] type Modifier = Document -- ^ Update operations on fields in a document. See diff --git a/mongoDB.cabal b/mongoDB.cabal index 9edd309..988920a 100644 --- a/mongoDB.cabal +++ b/mongoDB.cabal @@ -1,5 +1,5 @@ Name: mongoDB -Version: 2.0.2 +Version: 2.0.3 Synopsis: Driver (client) for MongoDB, a free, scalable, fast, document DBMS Description: This package lets you connect to MongoDB servers and