diff --git a/.travis.yml b/.travis.yml index d9e866d..8028713 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,20 @@ language: clojure sudo: required lein: lein +dist: xenial before_script: - - ./bin/ci/install_mongodb.sh + # Give MongoDB server some time to boot + - sleep 15 - mongod --version - ./bin/ci/before_script.sh script: lein do clean, javac, test jdk: - - oraclejdk8 - - oraclejdk9 + - openjdk10 + - oraclejdk11 + - openjdk12 services: - mongodb branches: only: - master - - 3.0.x-stable + - 3.5.x-stable diff --git a/ChangeLog.md b/ChangeLog.md index b3e1554..5ca646e 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,13 +1,31 @@ -## Changes between 3.1.x and 3.2.0 (unreleased) +## Changes between 3.5.x and 3.6.0 (unreleased) + +No changes yet. + + +## Changes between 3.1.x and 3.5.0 (Dec 10th, 2018) ### MongoDB Java Driver Update -MongoDB Java driver dependency has been updated to `3.4.x`. +MongoDB Java driver dependency has been updated to `3.9.x`. -This means that Monger now **requires JDK 7**. +This means that Monger now **requires JDK 8**. Contributed by @Linicks. +### 3rd Party Library Compatibility + + * Cheshire `5.8.x` + * clj-time `0.15.1` + * ring-core `0.15.1` + * Ragtime `0.7.x`. + +### URI Connection Usability Improvement + +URIs that don't specify a database will now be rejected as invalid. + +Contributed by Chris Broome. + ## Changes between 3.0.x and 3.1.0 (September 17th, 2016) diff --git a/README.md b/README.md index 7b717aa..fda4cf0 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,18 @@ [![Build Status](https://travis-ci.org/xingzhefeng/monger.svg?branch=master)](https://travis-ci.org/xingzhefeng/monger) Monger is an idiomatic [Clojure MongoDB driver](http://clojuremongodb.info) for a more civilized age. -It has batteries included, offers powerful expressive query DSL, strives to support every MongoDB 2.0+ feature and has sane defaults. Monger is built from for modern Clojure versions and sits on top of the official MongoDB Java driver. +It has batteries included, offers powerful expressive query DSL, +strives to support modern MongoDB features and have the "look and feel" and +flexibility of the MongoDB shell. + +Monger is built from for modern Clojure versions and sits on top of +the official MongoDB Java driver. ## Project Goals There is one MongoDB client for Clojure that has been around since 2009. So, why create another one? Monger authors -wanted a client that will +wanted a client that would * Support most of modern MongoDB features, focus on those that really matter. * Be [well documented](http://clojuremongodb.info). @@ -45,14 +50,14 @@ Maven, add the following repository definition to your `pom.xml`: With Leiningen: - [com.novemberain/monger "3.1.0"] + [com.novemberain/monger "3.5.0"] With Maven: com.novemberain monger - 3.1.0 + 3.5.0 @@ -70,15 +75,13 @@ questions, too! Please see our [documentation guides site](http://clojuremongodb.info/) and [API reference](http://reference.clojuremongodb.info). -Our [test -suite](https://github.com/michaelklishin/monger/tree/master/test/monger/test) +Our [test suite](https://github.com/michaelklishin/monger/tree/master/test/monger/test) also has many code examples. ## Community -[Monger has a mailing -list](https://groups.google.com/forum/#!forum/clojure-mongodb). Feel +[Monger has a mailing list](https://groups.google.com/forum/#!forum/clojure-mongodb). Feel free to join it and ask any questions you may have. To subscribe for announcements of releases, important changes and so @@ -88,14 +91,13 @@ on Twitter. ## Supported Clojure versions -Monger requires Clojure 1.6+. The most recent +Monger requires Clojure 1.8+. The most recent stable release is highly recommended. ## Continuous Integration Status [![Continuous Integration status](https://secure.travis-ci.org/michaelklishin/monger.svg)](http://travis-ci.org/michaelklishin/monger) -[![Dependencies Status](http://jarkeeper.com/michaelklishin/monger/status.svg)](http://jarkeeper.com/michaelklishin/monger) ## Monger Is a ClojureWerkz Project @@ -120,7 +122,7 @@ on Github. ## License -Copyright (C) 2011-2016 [Michael S. Klishin](http://twitter.com/michaelklishin), Alex Petrov, and the ClojureWerkz team. +Copyright (C) 2011-2018 [Michael S. Klishin](http://twitter.com/michaelklishin), Alex Petrov, and the ClojureWerkz team. Double licensed under the [Eclipse Public License](http://www.eclipse.org/legal/epl-v10.html) (the same as Clojure) or the [Apache Public License 2.0](http://www.apache.org/licenses/LICENSE-2.0.html). diff --git a/bin/ci/before_script.sh b/bin/ci/before_script.sh index 5bca8eb..fae6dd8 100755 --- a/bin/ci/before_script.sh +++ b/bin/ci/before_script.sh @@ -1,11 +1,8 @@ #!/bin/sh -# MongoDB seems to need some time to boot first. MK. -sleep 5 - # MongoDB Java driver won't run authentication twice on the same DB instance, # so we need to use multiple DBs. -mongo --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"]})' monger-test -mongo --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"]})' monger-test2 -mongo --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"]})' monger-test3 -mongo --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"]})' monger-test4 +mongo --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test +mongo --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test2 +mongo --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test3 +mongo --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test4 diff --git a/bin/ci/before_script_server_3.6.x.sh b/bin/ci/before_script_server_3.6.x.sh new file mode 100755 index 0000000..c8ffd7c --- /dev/null +++ b/bin/ci/before_script_server_3.6.x.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +# MongoDB seems to need some time to boot first. MK. +sleep 5 + +# MongoDB Java driver won't run authentication twice on the same DB instance, +# so we need to use multiple DBs. +mongo --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], passwordDigestor: "client"})' monger-test +mongo --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], passwordDigestor: "client"})' monger-test2 +mongo --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], passwordDigestor: "client"})' monger-test3 +mongo --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], passwordDigestor: "client"})' monger-test4 diff --git a/bin/ci/install_mongodb.sh b/bin/ci/install_mongodb.sh index 6645e06..b3d5a7a 100755 --- a/bin/ci/install_mongodb.sh +++ b/bin/ci/install_mongodb.sh @@ -1,8 +1,8 @@ #!/bin/sh -#sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10 -sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com --recv 0C49F3730359A14518585931BC711F9BA15703C6 -echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org.list +sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4 + +echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list sudo apt-get update sudo apt-get install -y mongodb-org diff --git a/project.clj b/project.clj index 4c92739..80dd2c1 100644 --- a/project.clj +++ b/project.clj @@ -1,11 +1,11 @@ -(defproject com.novemberain/monger "3.2.0-SNAPSHOT" +(defproject com.novemberain/monger "3.6.0-SNAPSHOT" :description "Monger is a Clojure MongoDB client for a more civilized age: friendly, flexible and with batteries included" :url "http://clojuremongodb.info" :min-lein-version "2.5.1" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} - :dependencies [[org.clojure/clojure "1.8.0"] - [org.mongodb/mongodb-driver "3.6.0-beta2"] + :dependencies [[org.clojure/clojure "1.9.0"] + [org.mongodb/mongodb-driver "3.9.1"] [clojurewerkz/support "1.1.0"]] :test-selectors {:default (fn [m] (and (not (:performance m)) @@ -27,35 +27,32 @@ :all (constantly true)} :source-paths ["src/clojure"] :java-source-paths ["src/java"] - :javac-options ["-target" "1.7" "-source" "1.7"] + :javac-options ["-target" "1.8" "-source" "1.8"] :mailing-list {:name "clojure-mongodb" :archive "https://groups.google.com/group/clojure-mongodb" :post "clojure-mongodb@googlegroups.com"} - :profiles {:dj02x {:dependencies [[org.clojure/data.json "0.2.6" :exclusions [org.clojure/clojure]]]} - :1.6 {:dependencies [[org.clojure/clojure "1.6.0"]]} - :1.7 {:dependencies [[org.clojure/clojure "1.7.0"]]} - :1.9 {:dependencies [[org.clojure/clojure "1.9.0-alpha13"]]} - :master {:dependencies [[org.clojure/clojure "1.9.0-master-SNAPSHOT"]]} + :profiles {:1.8 {:dependencies [[org.clojure/clojure "1.8.0"]]} + :master {:dependencies [[org.clojure/clojure "1.10.0-master-SNAPSHOT"]]} :dev {:resource-paths ["test/resources"] - :dependencies [[clj-time "0.8.0" :exclusions [org.clojure/clojure]] - [cheshire "5.5.0" :exclusions [org.clojure/clojure]] - [org.clojure/data.json "0.2.5" :exclusions [org.clojure/clojure]] - [org.clojure/tools.cli "0.3.1" :exclusions [org.clojure/clojure]] - [org.clojure/core.cache "0.6.3" :exclusions [org.clojure/clojure]] - [ring/ring-core "1.3.0" :exclusions [org.clojure/clojure]] - [com.novemberain/validateur "2.4.2" :exclusions [org.clojure/clojure]] - [ch.qos.logback/logback-classic "1.1.3" :exclusions [org.slf4j/slf4j-api]] - [ragtime/ragtime.core "0.3.7" :exclusions [org.clojure/clojure]]] - :plugins [[lein-codox "0.9.0"]] + :dependencies [[clj-time "0.15.1" :exclusions [org.clojure/clojure]] + [cheshire "5.8.1" :exclusions [org.clojure/clojure]] + [org.clojure/data.json "0.2.6" :exclusions [org.clojure/clojure]] + [org.clojure/tools.cli "0.4.1" :exclusions [org.clojure/clojure]] + [org.clojure/core.cache "0.7.1" :exclusions [org.clojure/clojure]] + [ring/ring-core "1.7.1" :exclusions [org.clojure/clojure]] + [com.novemberain/validateur "2.6.0" :exclusions [org.clojure/clojure]] + [ch.qos.logback/logback-classic "1.2.3" :exclusions [org.slf4j/slf4j-api]] + [ragtime/core "0.7.2" :exclusions [org.clojure/clojure]]] + :plugins [[lein-codox "0.10.5"]] :codox {:source-paths ["src/clojure"] :namespaces [#"^monger\.(?!internal)"]}} ;; only clj-time/JodaTime available, used to test monger.joda-time w/o clojure.data.json :dev2 {:resource-paths ["test/resources"] - :dependencies [[clj-time "0.8.0" :exclusions [org.clojure/clojure]]]}} - :aliases {"all" ["with-profile" "dev:dev,1.6:dev,1.8:dev,dj02x"]} - :repositories {"sonatype" {:url "http://oss.sonatype.org/content/repositories/releases" + :dependencies [[clj-time "0.15.1" :exclusions [org.clojure/clojure]]]}} + :aliases {"all" ["with-profile" "dev:dev,1.8:dev,master"]} + :repositories {"sonatype" {:url "https://oss.sonatype.org/content/repositories/releases" :snapshots false :releases {:checksum :fail :update :always}} - "sonatype-snapshots" {:url "http://oss.sonatype.org/content/repositories/snapshots" + "sonatype-snapshots" {:url "https://oss.sonatype.org/content/repositories/snapshots" :snapshots true :releases {:checksum :fail :update :always}}}) diff --git a/src/clojure/monger/cache.clj b/src/clojure/monger/cache.clj index 4156b38..b4f4b72 100644 --- a/src/clojure/monger/cache.clj +++ b/src/clojure/monger/cache.clj @@ -4,7 +4,7 @@ ;; The APL v2.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team ;; ;; Licensed under the Apache License, Version 2.0 (the "License"); ;; you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ ;; The EPL v1.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. ;; All rights reserved. ;; ;; This program and the accompanying materials are made available under the terms of diff --git a/src/clojure/monger/collection.clj b/src/clojure/monger/collection.clj index 0a50e97..df7a6c1 100644 --- a/src/clojure/monger/collection.clj +++ b/src/clojure/monger/collection.clj @@ -4,7 +4,7 @@ ;; The APL v2.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team ;; Copyright (c) 2012 Toby Hede ;; Copyright (c) 2012 Baishampayan Ghose ;; @@ -24,7 +24,7 @@ ;; The EPL v1.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. ;; Copyright (c) 2012 Toby Hede ;; Copyright (c) 2012 Baishampayan Ghose ;; diff --git a/src/clojure/monger/command.clj b/src/clojure/monger/command.clj index 6f823a9..c349e75 100644 --- a/src/clojure/monger/command.clj +++ b/src/clojure/monger/command.clj @@ -4,7 +4,7 @@ ;; The APL v2.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team ;; Copyright (c) 2012 Toby Hede ;; ;; Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,7 +23,7 @@ ;; The EPL v1.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. ;; Copyright (c) 2012 Toby Hede ;; All rights reserved. ;; diff --git a/src/clojure/monger/constraints.clj b/src/clojure/monger/constraints.clj index 3eb39c2..41e66f0 100644 --- a/src/clojure/monger/constraints.clj +++ b/src/clojure/monger/constraints.clj @@ -4,7 +4,7 @@ ;; The APL v2.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team ;; ;; Licensed under the Apache License, Version 2.0 (the "License"); ;; you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ ;; The EPL v1.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. ;; All rights reserved. ;; ;; This program and the accompanying materials are made available under the terms of diff --git a/src/clojure/monger/conversion.clj b/src/clojure/monger/conversion.clj index 02e97a5..729b09f 100644 --- a/src/clojure/monger/conversion.clj +++ b/src/clojure/monger/conversion.clj @@ -5,7 +5,7 @@ ;; ;; ---------------------------------------------------------------------------------- ;; Portions of the code are Copyright (c) 2009 Andrew Boekhoff -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team ;; ;; Licensed under the Apache License, Version 2.0 (the "License"); ;; you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ ;; ;; ---------------------------------------------------------------------------------- ;; Portions of the code are Copyright (c) 2009 Andrew Boekhoff -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. ;; All rights reserved. ;; ;; This program and the accompanying materials are made available under the terms of diff --git a/src/clojure/monger/core.clj b/src/clojure/monger/core.clj index d7589ef..e5314a0 100644 --- a/src/clojure/monger/core.clj +++ b/src/clojure/monger/core.clj @@ -4,7 +4,7 @@ ;; The APL v2.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team ;; ;; Licensed under the Apache License, Version 2.0 (the "License"); ;; you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ ;; The EPL v1.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. ;; All rights reserved. ;; ;; This program and the accompanying materials are made available under the terms of @@ -233,10 +233,11 @@ Commonly used for PaaS-based applications, for example, running on Heroku. If username and password are provided, performs authentication." [^String uri-string] - (let [uri (MongoClientURI. uri-string) - conn (MongoClient. uri) - db (.getDB conn (.getDatabase uri))] - {:conn conn :db db})) + (let [uri (MongoClientURI. uri-string) + conn (MongoClient. uri)] + (if-let [dbName (.getDatabase uri)] + {:conn conn :db (.getDB conn dbName)} + (throw (IllegalArgumentException. "No database name specified in URI. Monger requires a database to be explicitly configured."))))) (defn ^com.mongodb.CommandResult command "Runs a database command (please check MongoDB documentation for the complete list of commands). diff --git a/src/clojure/monger/credentials.clj b/src/clojure/monger/credentials.clj index 856dc67..009145f 100644 --- a/src/clojure/monger/credentials.clj +++ b/src/clojure/monger/credentials.clj @@ -4,7 +4,7 @@ ;; The APL v2.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team ;; ;; Licensed under the Apache License, Version 2.0 (the "License"); ;; you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ ;; The EPL v1.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. ;; All rights reserved. ;; ;; This program and the accompanying materials are made available under the terms of diff --git a/src/clojure/monger/cursor.clj b/src/clojure/monger/cursor.clj index 39acb43..dc102c7 100644 --- a/src/clojure/monger/cursor.clj +++ b/src/clojure/monger/cursor.clj @@ -4,7 +4,7 @@ ;; The APL v2.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team ;; ;; Licensed under the Apache License, Version 2.0 (the "License"); ;; you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ ;; The EPL v1.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. ;; All rights reserved. ;; ;; This program and the accompanying materials are made available under the terms of diff --git a/src/clojure/monger/db.clj b/src/clojure/monger/db.clj index cdaca66..19d6305 100644 --- a/src/clojure/monger/db.clj +++ b/src/clojure/monger/db.clj @@ -4,7 +4,7 @@ ;; The APL v2.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team ;; Copyright (c) 2012 Toby Hede ;; ;; Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,7 +23,7 @@ ;; The EPL v1.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. ;; Copyright (c) 2012 Toby Hede ;; All rights reserved. ;; diff --git a/src/clojure/monger/gridfs.clj b/src/clojure/monger/gridfs.clj index a3f60f9..e42c168 100644 --- a/src/clojure/monger/gridfs.clj +++ b/src/clojure/monger/gridfs.clj @@ -4,7 +4,7 @@ ;; The APL v2.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team ;; ;; Licensed under the Apache License, Version 2.0 (the "License"); ;; you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ ;; The EPL v1.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. ;; All rights reserved. ;; ;; This program and the accompanying materials are made available under the terms of diff --git a/src/clojure/monger/internal/pagination.clj b/src/clojure/monger/internal/pagination.clj index b5b3259..dab3032 100644 --- a/src/clojure/monger/internal/pagination.clj +++ b/src/clojure/monger/internal/pagination.clj @@ -4,7 +4,7 @@ ;; The APL v2.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team ;; ;; Licensed under the Apache License, Version 2.0 (the "License"); ;; you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ ;; The EPL v1.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. ;; All rights reserved. ;; ;; This program and the accompanying materials are made available under the terms of diff --git a/src/clojure/monger/joda_time.clj b/src/clojure/monger/joda_time.clj index 940ca3e..dd563a2 100644 --- a/src/clojure/monger/joda_time.clj +++ b/src/clojure/monger/joda_time.clj @@ -4,7 +4,7 @@ ;; The APL v2.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team ;; ;; Licensed under the Apache License, Version 2.0 (the "License"); ;; you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ ;; The EPL v1.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. ;; All rights reserved. ;; ;; This program and the accompanying materials are made available under the terms of diff --git a/src/clojure/monger/js.clj b/src/clojure/monger/js.clj index 51f8da7..32ab680 100644 --- a/src/clojure/monger/js.clj +++ b/src/clojure/monger/js.clj @@ -4,7 +4,7 @@ ;; The APL v2.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team ;; ;; Licensed under the Apache License, Version 2.0 (the "License"); ;; you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ ;; The EPL v1.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. ;; All rights reserved. ;; ;; This program and the accompanying materials are made available under the terms of diff --git a/src/clojure/monger/json.clj b/src/clojure/monger/json.clj index 4fb14d8..ceaba68 100644 --- a/src/clojure/monger/json.clj +++ b/src/clojure/monger/json.clj @@ -4,7 +4,7 @@ ;; The APL v2.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team ;; ;; Licensed under the Apache License, Version 2.0 (the "License"); ;; you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ ;; The EPL v1.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. ;; All rights reserved. ;; ;; This program and the accompanying materials are made available under the terms of diff --git a/src/clojure/monger/operators.clj b/src/clojure/monger/operators.clj index ae4a828..27c3016 100644 --- a/src/clojure/monger/operators.clj +++ b/src/clojure/monger/operators.clj @@ -4,7 +4,7 @@ ;; The APL v2.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team ;; ;; Licensed under the Apache License, Version 2.0 (the "License"); ;; you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ ;; The EPL v1.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. ;; All rights reserved. ;; ;; This program and the accompanying materials are made available under the terms of @@ -184,6 +184,9 @@ ;; (mgcol/update "docs" { :_id oid } { $push { :tags "modifiers" } }) (defoperator $push) +;; $position modifies the behavior of $push per https://docs.mongodb.com/manual/reference/operator/update/position/ +(defoperator $position) + ;; $each is a modifier for the $push and $addToSet operators for appending multiple values to an array field. ;; Without the $each modifier $push and $addToSet will append an array as a single value. ;; MongoDB 2.4 adds support for the $each modifier to the $push operator. @@ -193,14 +196,6 @@ ;; (mgcol/update coll { :_id oid } { $push { :tags { $each ["mongodb" "docs"] } } }) (defoperator $each) -;; $pushAll appends each value in value_array to field, if field is an existing array, otherwise sets field to the array value_array -;; if field is not present. If field is present but is not an array, an error condition is raised. -;; Deprecated since MongoDB 2.4, $push with $each modifier should be used instead. -;; -;; EXAMPLES: -;; (mgcol/update coll { :_id oid } { $pushAll { :tags ["mongodb" "docs"] } }) -(defoperator $pushAll) - ;; $addToSet Adds value to the array only if its not in the array already, if field is an existing array, otherwise sets field to the ;; array value if field is not present. If field is present but is not an array, an error condition is raised. ;; diff --git a/src/clojure/monger/query.clj b/src/clojure/monger/query.clj index e8caa65..7320722 100644 --- a/src/clojure/monger/query.clj +++ b/src/clojure/monger/query.clj @@ -4,7 +4,7 @@ ;; The APL v2.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team ;; ;; Licensed under the Apache License, Version 2.0 (the "License"); ;; you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ ;; The EPL v1.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. ;; All rights reserved. ;; ;; This program and the accompanying materials are made available under the terms of @@ -43,6 +43,7 @@ [monger.conversion :refer :all] [monger.operators :refer :all]) (:import [com.mongodb DB DBCollection DBObject DBCursor ReadPreference] + [java.util.concurrent TimeUnit] java.util.List)) @@ -96,6 +97,7 @@ snapshot read-preference keywordize-fields + max-time options] :or { limit 0 batch-size 256 skip 0 } }] (with-open [cursor (doto (.find collection (to-db-object query) (as-field-selector fields)) @@ -109,6 +111,8 @@ (.hint cursor (to-db-object hint))) (when read-preference (.setReadPreference cursor read-preference)) + (when max-time + (.maxTime cursor max-time TimeUnit/MILLISECONDS)) (when options (add-options cursor options)) (map (fn [x] (from-db-object x keywordize-fields)) @@ -154,6 +158,10 @@ [m ^ReadPreference rp] (merge m { :read-preference rp })) +(defn max-time + [m ^long max-time] + (merge m { :max-time max-time })) + (defn options [m opts] (merge m { :options opts })) diff --git a/src/clojure/monger/ragtime.clj b/src/clojure/monger/ragtime.clj index 71db197..94a2d27 100644 --- a/src/clojure/monger/ragtime.clj +++ b/src/clojure/monger/ragtime.clj @@ -4,7 +4,7 @@ ;; The APL v2.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team ;; ;; Licensed under the Apache License, Version 2.0 (the "License"); ;; you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ ;; The EPL v1.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. ;; All rights reserved. ;; ;; This program and the accompanying materials are made available under the terms of @@ -34,7 +34,7 @@ (ns monger.ragtime "Ragtime integration" (:refer-clojure :exclude [find sort]) - (:require [ragtime.core :as ragtime] + (:require [ragtime.protocols :as proto] [monger.core :as mg] [monger.collection :as mc] [monger.query :refer [with-collection find sort]]) @@ -47,7 +47,7 @@ (extend-type com.mongodb.DB - ragtime/Migratable + proto/DataStore (add-migration-id [db id] (mc/insert db migrations-collection {:_id id :created_at (Date.)} WriteConcern/FSYNC_SAFE)) (remove-migration-id [db id] diff --git a/src/clojure/monger/result.clj b/src/clojure/monger/result.clj index 1663e18..1a4c9f9 100644 --- a/src/clojure/monger/result.clj +++ b/src/clojure/monger/result.clj @@ -4,7 +4,7 @@ ;; The APL v2.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team ;; ;; Licensed under the Apache License, Version 2.0 (the "License"); ;; you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ ;; The EPL v1.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. ;; All rights reserved. ;; ;; This program and the accompanying materials are made available under the terms of diff --git a/src/clojure/monger/ring/session_store.clj b/src/clojure/monger/ring/session_store.clj index 76ff459..0b316ae 100644 --- a/src/clojure/monger/ring/session_store.clj +++ b/src/clojure/monger/ring/session_store.clj @@ -4,7 +4,7 @@ ;; The APL v2.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team ;; ;; Licensed under the Apache License, Version 2.0 (the "License"); ;; you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ ;; The EPL v1.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. ;; All rights reserved. ;; ;; This program and the accompanying materials are made available under the terms of diff --git a/src/clojure/monger/util.clj b/src/clojure/monger/util.clj index 70aeb4f..40ffe7b 100644 --- a/src/clojure/monger/util.clj +++ b/src/clojure/monger/util.clj @@ -4,7 +4,7 @@ ;; The APL v2.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team ;; ;; Licensed under the Apache License, Version 2.0 (the "License"); ;; you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ ;; The EPL v1.0: ;; ;; ---------------------------------------------------------------------------------- -;; Copyright (c) 2011-2015 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. +;; Copyright (c) 2011-2018 Michael S. Klishin, Alex Petrov, and the ClojureWerkz Team. ;; All rights reserved. ;; ;; This program and the accompanying materials are made available under the terms of diff --git a/test/monger/test/atomic_modifiers_test.clj b/test/monger/test/atomic_modifiers_test.clj index 0eb6fbb..23cdacb 100644 --- a/test/monger/test/atomic_modifiers_test.clj +++ b/test/monger/test/atomic_modifiers_test.clj @@ -174,7 +174,7 @@ ;; this is a common mistake, I leave it here to demonstrate it. You almost never - ;; actually want to do this! What you really want is to use $pushAll instead of $push. MK. + ;; actually want to do this! What you really want is to use $push with $each instead of $push. MK. (deftest add-array-value-to-an-existing-array-using-$push-modifier (let [coll "docs" oid (ObjectId.) @@ -228,34 +228,34 @@ (mc/find-map-by-id db coll oid))))) ;; - ;; $pushAll + ;; $push + $each (formerly $pushAll) ;; - (deftest initialize-an-array-using-$pushAll-modifier + (deftest initialize-an-array-using-$push-and-$each-modifiers (let [coll "docs" oid (ObjectId.) title "$pushAll modifier appends multiple values to field"] (mc/insert db coll {:_id oid :title title}) - (mc/update db coll {:_id oid} {$pushAll {:tags ["mongodb" "docs"]}}) + (mc/update db coll {:_id oid} {$push {:tags {$each ["mongodb" "docs"]}}}) (is (= {:_id oid :title title :tags ["mongodb" "docs"]} (mc/find-map-by-id db coll oid))))) - (deftest add-value-to-an-existing-array-using-$pushAll-modifier + (deftest add-value-to-an-existing-array-using-$push-and-$each-modifier (let [coll "docs" oid (ObjectId.) title "$pushAll modifier appends multiple values to field"] (mc/insert db coll {:_id oid :title title :tags ["mongodb"]}) - (mc/update db coll {:_id oid} {$pushAll {:tags ["modifiers" "docs"]}}) + (mc/update db coll {:_id oid} {$push {:tags {$each ["modifiers" "docs"]}}}) (is (= {:_id oid :title title :tags ["mongodb" "modifiers" "docs"]} (mc/find-map-by-id db coll oid))))) - (deftest double-add-value-to-an-existing-array-using-$pushAll-modifier + (deftest double-add-value-to-an-existing-array-using-$push-and-$each-modifier (let [coll "docs" oid (ObjectId.) title "$pushAll modifier appends multiple values to field"] (mc/insert db coll {:_id oid :title title :tags ["mongodb" "docs"]}) - (mc/update db coll {:_id oid} {$pushAll {:tags ["modifiers" "docs"]}}) + (mc/update db coll {:_id oid} {$push {:tags {$each ["modifiers" "docs"]}}}) (is (= {:_id oid :title title :tags ["mongodb" "docs" "modifiers" "docs"]} (mc/find-map-by-id db coll oid))))) diff --git a/test/monger/test/authentication_test.clj b/test/monger/test/authentication_test.clj index e8d5447..06acb7b 100644 --- a/test/monger/test/authentication_test.clj +++ b/test/monger/test/authentication_test.clj @@ -15,7 +15,7 @@ (is (-> conn .getAddress (.sameHost "127.0.0.1"))))) (deftest ^{:authentication true} connect-to-mongo-via-uri-with-valid-credentials - (let [{:keys [conn db]} (mg/connect-via-uri "mongodb://clojurewerkz/monger:monger@127.0.0.1/monger-test4")] + (let [{:keys [conn db]} (mg/connect-via-uri "mongodb://clojurewerkz%2Fmonger:monger@127.0.0.1/monger-test4")] (is (= "monger-test4" (.getName db))) (is (-> conn .getAddress (.sameHost "127.0.0.1"))) (mc/remove db "documents") diff --git a/test/monger/test/cache_test.clj b/test/monger/test/cache_test.clj deleted file mode 100644 index 0845af0..0000000 --- a/test/monger/test/cache_test.clj +++ /dev/null @@ -1,126 +0,0 @@ -(ns monger.test.cache-test - (:require [monger.core :as mg] - [monger.collection :as mc] - [clojure.core.cache :refer :all] - [clojure.test :refer :all] - [monger.cache :refer :all]) - (:import [clojure.core.cache BasicCache FIFOCache LRUCache TTLCache] - java.util.UUID)) - -;; -;; Playground/Tests. These were necessary because clojure.core.cache has -;; little documentation, incomplete test suite and -;; slightly non-standard (although necessary to support all those cache variations) -;; cache operations protocol. -;; -;; This is by no means clear or complete either but it did the job of helping me -;; explore the API. - -(deftest ^{:cache true} - test-has?-with-basic-cache - (testing "that has? returns false for misses" - (let [c (BasicCache. {})] - (are [v] (is (false? (has? c v))) - :missing-key - "missing-key" - (gensym "missing-key")))) - (testing "that has? returns true for hits" - (let [c (BasicCache. {:skey "Value" :lkey (Long/valueOf 10000) "kkey" :keyword})] - (are [v] (is (has? c v)) - :skey - :lkey - "kkey")))) - - -(deftest ^{:cache true} - test-lookup-with-basic-cache - (testing "that lookup returns nil for misses" - (let [c (BasicCache. {})] - (are [v] (is (nil? (lookup c v))) - :missing-key - "missing-key" - (gensym "missing-key")))) - (testing "that lookup returns cached values for hits" - (let [l (Long/valueOf 10000) - c (BasicCache. {:skey "Value" :lkey l "kkey" :keyword})] - (are [v k] (is (= v (lookup c k))) - "Value" :skey - l :lkey - :keyword "kkey")))) - -(deftest ^{:cache true} - test-evict-with-basic-cache - (testing "that evict has no effect for keys that do not exist" - (let [c (atom (BasicCache. {:a 1 :b 2}))] - (swap! c evict :missing-key) - (is (has? @c :a)) - (is (has? @c :b)))) - (testing "that evict removes keys that did exist" - (let [c (atom (BasicCache. {:skey "Value" "kkey" :keyword}))] - (is (has? @c :skey)) - (is (= "Value" (lookup @c :skey))) - (swap! c evict :skey) - (is (not (has? @c :skey))) - (is (= nil (lookup @c :skey))) - (is (has? @c "kkey")) - (is (= :keyword (lookup @c "kkey")))))) - -(deftest ^{:cache true} - test-seed-with-basic-cache - (testing "that seed returns a new value" - (let [c (atom (BasicCache. {}))] - (swap! c seed {:a 1 :b "b" "c" :d}) - (are [k v] (do - (is (has? @c k)) - (is (= v (lookup @c k)))) - :a 1 - :b "b" - "c" :d)))) - - -;; -;; Tests -;; - -(let [conn (mg/connect) - db (mg/get-db conn "monger-test")] - (use-fixtures :each (fn [f] - (mc/remove db "basic_monger_cache_entries") - (f) - (mc/remove db "basic_monger_cache_entries"))) - - - (deftest ^{:cache true} - test-has?-with-basic-monger-cache - (testing "that has? returns false for misses" - (let [coll "basic_monger_cache_entries" - c (basic-monger-cache-factory db coll)] - (is (not (has? c (str (UUID/randomUUID))))) - (is (not (has? c (str (UUID/randomUUID))))))) - (testing "that has? returns true for hits" - (let [coll "basic_monger_cache_entries" - c (basic-monger-cache-factory db coll {"a" 1 "b" "cache" "c" 3/4})] - (is (has? c "a")) - (is (has? c "b")) - (is (has? c "c")) - (is (not (has? c "d")))))) - - - (deftest ^{:cache true} - test-lookup-with-basic-monger-cache - (testing "that lookup returns nil for misses" - (let [coll "basic_monger_cache_entries" - c (basic-monger-cache-factory db coll)] - (are [v] (is (nil? (lookup c v))) - :missing-key - "missing-key" - (gensym "missing-key")))) - (testing "that lookup returns cached values for hits" - (let [l (Long/valueOf 10000) - coll "basic_monger_cache_entries" - c (basic-monger-cache-factory db coll {:skey "Value" :lkey l "kkey" :keyword})] - (are [v k] (is (= v (lookup c k))) - "Value" :skey - l :lkey - "keyword" "kkey"))))) - diff --git a/test/monger/test/core_test.clj b/test/monger/test/core_test.clj index eeaa5b6..02f45dc 100644 --- a/test/monger/test/core_test.clj +++ b/test/monger/test/core_test.clj @@ -70,3 +70,7 @@ :cursor-finalizer-enabled true :required-replica-set-name "rs"}] (is (instance? com.mongodb.MongoClientOptions$Builder (mg/mongo-options-builder opts))))) + +(deftest connect-to-uri-without-db-name + (let [uri "mongodb://localhost:27017"] + (is (thrown? IllegalArgumentException (mg/connect-via-uri uri))))) diff --git a/test/monger/test/ragtime_test.clj b/test/monger/test/ragtime_test.clj index c972396..9a6b448 100644 --- a/test/monger/test/ragtime_test.clj +++ b/test/monger/test/ragtime_test.clj @@ -2,7 +2,7 @@ (:require [monger.core :as mg] [monger.collection :as mc] monger.ragtime - [ragtime.core :refer :all] + [ragtime.protocols :refer :all] [clojure.test :refer :all]))