diff --git a/ChangeLog.md b/ChangeLog.md index b11712c..0bc55b0 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,10 @@ ## Changes between 1.0.0-beta4 and 1.0.0-beta5 +### Clojure sets now can be serialized + +Monger now supports serialization for all classes that implement `java.util.Set`, including Clojure sets. + + ### Capped collection support `monger.collection/create` provides a way to create collections with fine-tuned attributes (for example, capped collections) diff --git a/src/monger/conversion.clj b/src/monger/conversion.clj index 6699abb..a036c31 100644 --- a/src/monger/conversion.clj +++ b/src/monger/conversion.clj @@ -23,8 +23,8 @@ (ns monger.conversion (:import [com.mongodb DBObject BasicDBObject BasicDBList DBCursor] - [clojure.lang IPersistentMap Named Ratio] - [java.util List Map Date] + [clojure.lang IPersistentMap Named Keyword Ratio] + [java.util List Map Date Set] org.bson.types.ObjectId)) (defprotocol ConvertToDBObject @@ -35,10 +35,6 @@ (to-db-object [input] input) - Object - (to-db-object [input] - input) - String (to-db-object [^String input] input) @@ -51,6 +47,9 @@ (to-db-object [^Ratio input] (double input)) + Keyword + (to-db-object [^Keyword input] (.getName input)) + Named (to-db-object [^Named input] (.getName input)) @@ -64,8 +63,15 @@ List (to-db-object [^List input] (map to-db-object input)) + Set + (to-db-object [^Set input] (map to-db-object input)) + DBObject - (to-db-object [^DBObject input] input)) + (to-db-object [^DBObject input] input) + + Object + (to-db-object [input] + input)) diff --git a/test/monger/test/inserting_test.clj b/test/monger/test/inserting_test.clj index 65c20b7..4764eed 100644 --- a/test/monger/test/inserting_test.clj +++ b/test/monger/test/inserting_test.clj @@ -67,7 +67,15 @@ id (ObjectId.) doc { :keyword :kwd "_id" id } result (mgcol/insert "widgets" doc)] - (is (= (name :kwd) (:keyword (mgcol/find-map-by-id collection id)))))) ; + (is (= (name :kwd) (:keyword (mgcol/find-map-by-id collection id)))))) + +(deftest insert-a-document-with-clojure-keyword-in-a-set-in-it + (let [collection "widgets" + id (ObjectId.) + doc { :keyword1 {:keyword2 #{:kw1 :kw2}} "_id" id } + result (mgcol/insert "widgets" doc)] + (is (= (sort ["kw1" "kw2"]) + (sort (get-in (mgcol/find-map-by-id collection id) [:keyword1 :keyword2])))))) (defrecord Metrics