bump version; update change log; some tests for aggregations and docs
This commit is contained in:
parent
5435a5afa8
commit
cddcae94e6
6 changed files with 45 additions and 8 deletions
|
|
@ -1,6 +1,13 @@
|
||||||
# Change Log
|
# Change Log
|
||||||
All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/).
|
All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/).
|
||||||
|
|
||||||
|
## 0.7.0 - 2022-10-04
|
||||||
|
### Added
|
||||||
|
- Support reading dates as instances (thanks @henryw374)
|
||||||
|
- Support data literal for mongo id (thanks @henryw374)
|
||||||
|
- Support for implicit transactions (thanks @AdamClements)
|
||||||
|
- Support for aggregation pipeline in find-one-and-update (requires 4.2+, thanks @jacobemcken)
|
||||||
|
|
||||||
## 0.6.0 - 2020-01-10
|
## 0.6.0 - 2020-01-10
|
||||||
### Added
|
### Added
|
||||||
- Support for bulk-write
|
- Support for bulk-write
|
||||||
|
|
|
||||||
14
README.md
14
README.md
|
|
@ -23,7 +23,7 @@ It was developed with the following goals:
|
||||||
|
|
||||||
## Status
|
## Status
|
||||||
|
|
||||||
mongo-driver-3 is used in production, but is also under development and the API may change slightly.
|
mongo-driver-3 is used in production, and the existing public API will be maintained.
|
||||||
Please try it out and raise any issues you may find.
|
Please try it out and raise any issues you may find.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
@ -32,10 +32,10 @@ For Leinengen, add this to your project.clj:
|
||||||
|
|
||||||
```clojure
|
```clojure
|
||||||
;; The underlying driver -- any newer version can also be used
|
;; The underlying driver -- any newer version can also be used
|
||||||
[org.mongodb/mongodb-driver-sync "3.11.2"]
|
[org.mongodb/mongodb-driver-sync "4.2.3"]
|
||||||
|
|
||||||
;; This wrapper library
|
;; This wrapper library
|
||||||
[mongo-driver-3 "0.5.0"]
|
[mongo-driver-3 "0.6.0"]
|
||||||
```
|
```
|
||||||
|
|
||||||
## Getting started
|
## Getting started
|
||||||
|
|
@ -171,6 +171,14 @@ use `with-open` so the session is closed after both successful and failed transa
|
||||||
(fn []
|
(fn []
|
||||||
(mc/insert-one my-db "coll" {:name "hello"} {:session s})
|
(mc/insert-one my-db "coll" {:name "hello"} {:session s})
|
||||||
(mc/insert-one my-db "coll" {:name "world"} {:session s}))))
|
(mc/insert-one my-db "coll" {:name "world"} {:session s}))))
|
||||||
|
|
||||||
|
;; There is also a helper method to make this easier,
|
||||||
|
;; where it is not necessary to manually open or pass a session:
|
||||||
|
(mg/with-implicit-transaction
|
||||||
|
{:client client}
|
||||||
|
(fn []
|
||||||
|
(mc/insert-one my-db "coll" {:name "hello"})
|
||||||
|
(mc/insert-one my-db "coll" {:name "world"})))
|
||||||
```
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
(defproject mongo-driver-3 "0.6.1-SNAPSHOT"
|
(defproject mongo-driver-3 "0.7.0-SNAPSHOT"
|
||||||
:description "A Clojure wrapper for the Java MongoDB driver 3.11/4.0+."
|
:description "A Clojure wrapper for the Java MongoDB driver 3.11/4.0+."
|
||||||
:url "https://github.com/gnarroway/mongo-driver-3"
|
:url "https://github.com/gnarroway/mongo-driver-3"
|
||||||
:license {:name "The MIT License"
|
:license {:name "The MIT License"
|
||||||
|
|
|
||||||
|
|
@ -150,7 +150,24 @@
|
||||||
|
|
||||||
(defn with-implicit-transaction
|
(defn with-implicit-transaction
|
||||||
"Automatically sets the session / transaction for all mongo operations
|
"Automatically sets the session / transaction for all mongo operations
|
||||||
within the scope, using a dynamic binding"
|
within the scope, using a dynamic binding.
|
||||||
|
|
||||||
|
The first argument is an options map with keys:
|
||||||
|
|
||||||
|
- `:client` a MongoClient (mandatory)
|
||||||
|
- `:transaction-opts` (see `->TransactionOptions` for keys)
|
||||||
|
- `:session-opts` (see `start-session` for details)
|
||||||
|
|
||||||
|
The second argument `body` is a fn with one or more mongo operations in it.
|
||||||
|
e.g.
|
||||||
|
|
||||||
|
```
|
||||||
|
(mg/with-implicit-transaction
|
||||||
|
{:client client}
|
||||||
|
(fn []
|
||||||
|
(mc/insert-one my-db \"coll\" {:name \"hello\"})
|
||||||
|
(mc/insert-one my-db \"coll\" {:name \"world\"})))
|
||||||
|
```"
|
||||||
[{:keys [^MongoClient client transaction-opts session-opts] :or {transaction-opts {} session-opts {}}} body]
|
[{:keys [^MongoClient client transaction-opts session-opts] :or {transaction-opts {} session-opts {}}} body]
|
||||||
(with-open [^ClientSession session (start-session client session-opts)]
|
(with-open [^ClientSession session (start-session client session-opts)]
|
||||||
(binding [*session* session]
|
(binding [*session* session]
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,7 @@
|
||||||
(:import (com.mongodb MongoNamespace)
|
(:import (com.mongodb MongoNamespace)
|
||||||
(com.mongodb.client MongoDatabase MongoCollection ClientSession)
|
(com.mongodb.client MongoDatabase MongoCollection ClientSession)
|
||||||
(com.mongodb.client.model IndexModel)
|
(com.mongodb.client.model IndexModel)
|
||||||
(java.util List)
|
(java.util List)))
|
||||||
(org.bson Document)))
|
|
||||||
|
|
||||||
(set! *warn-on-reflection* true)
|
(set! *warn-on-reflection* true)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -216,7 +216,13 @@
|
||||||
(let [db (new-db @client)]
|
(let [db (new-db @client)]
|
||||||
|
|
||||||
(is (nil? (dissoc (mc/find-one-and-update db "test" {:id 1} {:$set {:r 1}} {:return-new? true}) :_id)))
|
(is (nil? (dissoc (mc/find-one-and-update db "test" {:id 1} {:$set {:r 1}} {:return-new? true}) :_id)))
|
||||||
(is (= {:id 1 :r 1} (dissoc (mc/find-one-and-update db "test" {:id 1} {:$set {:r 1}} {:return-new? true :upsert? true}) :_id))))))
|
(is (= {:id 1 :r 1} (dissoc (mc/find-one-and-update db "test" {:id 1} {:$set {:r 1}} {:return-new? true :upsert? true}) :_id)))))
|
||||||
|
|
||||||
|
(testing "aggregation pipeline"
|
||||||
|
(let [db (new-db @client)
|
||||||
|
_ (mc/insert-many db "test" [{:id 1 :a [1 2] :b []} {:id 2 :a [7 8] :b []}])]
|
||||||
|
|
||||||
|
(is (= {:id 1 :a [] :b [1 2]} (dissoc (mc/find-one-and-update db "test" {:id 1} [{:$set {:b :$a}} {:$set {:a []}}] {:return-new? true}) :_id))))))
|
||||||
|
|
||||||
(deftest ^:integration test-find-one-and-replace
|
(deftest ^:integration test-find-one-and-replace
|
||||||
(testing "return new"
|
(testing "return new"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue