diff --git a/project.clj b/project.clj index 34f5848..6fee7e1 100644 --- a/project.clj +++ b/project.clj @@ -5,7 +5,7 @@ :url "https://www.eclipse.org/legal/epl-2.0/"} :signing {:gpg-key "helpshift-clojars-admin"} :dependencies [[org.clojure/clojure "1.10.0"] - [org.mongodb/mongodb-driver-sync "4.1.1"] + [org.mongodb/mongodb-driver-sync "4.8.0"] [org.clojure/tools.logging "1.1.0"]] :repl-options {:init-ns mongrove.core} :jvm-opts ^:replace ["-Duser.timezone=UTC" diff --git a/src/mongrove/core.clj b/src/mongrove/core.clj index 441966d..62de562 100644 --- a/src/mongrove/core.clj +++ b/src/mongrove/core.clj @@ -374,6 +374,23 @@ (.countDocuments collection bson-query))))) +(defn ^:public-api distinct-vals + "Gets the distinct values for a field name that matches the filter." + ([^MongoDatabase db + ^String coll + ^String field-name + ^Class class-type + filter & {:keys [session]}] + (let [collection (get-collection db coll) + bson-filter (conversion/to-bson-document filter) + ^DistinctIterable iterator + (if session + (.distinct ^MongoCollection collection session field-name bson-filter class-type) + (.distinct ^MongoCollection collection field-name bson-filter class-type)) + cursor (.cursor iterator)] + (iterator-seq cursor)))) + + (defn ^:public-api delete "Delete a document from the collection that matches `query`. wc is the write-concern which should be a key from write-concern-map and is optional.