Skip to content

Commit

Permalink
Merge pull request #114 from stereoderevo/Keywordise_find_maps
Browse files Browse the repository at this point in the history
Keywordise find maps
  • Loading branch information
michaelklishin committed Aug 25, 2015
2 parents e0c632f + ee0c3db commit 5f53732
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -10,3 +10,5 @@ deploy.docs.sh
target/*
todo.org
.nrepl-*
.idea/
*.iml
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -109,7 +109,8 @@ Monger is part of the [group of Clojure libraries known as ClojureWerkz](http://

Monger uses [Leiningen 2](https://github.com/technomancy/leiningen/blob/master/doc/TUTORIAL.md). Make sure you have it installed and then run tests against
supported Clojure versions using


./bin/ci/before_script.sh
lein all do clean, javac, test

Then create a branch and make your changes on it. Once you are done with your changes and all tests pass, submit a pull request
Expand Down
4 changes: 3 additions & 1 deletion src/clojure/monger/collection.clj
Expand Up @@ -147,8 +147,10 @@
(with-open [dbc (find db coll ref)]
(map (fn [x] (from-db-object x true)) dbc)))
([^DB db ^String coll ^Map ref fields]
(find-maps db coll ref fields true))
([^DB db ^String coll ^Map ref fields keywordize]
(with-open [dbc (find db coll ref fields)]
(map (fn [x] (from-db-object x true)) dbc))))
(map (fn [x] (from-db-object x keywordize)) dbc))))

(defn find-seq
"Queries for objects in this collection, returns ISeq of DBObjects."
Expand Down
10 changes: 9 additions & 1 deletion test/monger/test/regular_finders_test.clj
Expand Up @@ -281,4 +281,12 @@
(doseq [i clojure-libs]
(let [doc (mgcnv/from-db-object i true)]
(is (= (:language doc) "Clojure"))))
(is (empty? (mc/find db collection { :language "Erlang" } [:name])))))))
(is (empty? (mc/find db collection { :language "Erlang" } [:name]))))))

(deftest find-maps-with-keywordize-false
(let [collection "libraries"]
(mc/insert-batch db collection [{ :language "Clojure", :name "monger" }
{ :language "Clojure", :name "langohr" }])
(let [results (mc/find-maps db collection {:name "langohr"} [] false)]
(is (= 1 (.count results)))
(is (= (get (first results) "language") "Clojure"))))))

0 comments on commit 5f53732

Please sign in to comment.