mongodbclojuremonger

Keyword item in monger vector is converted to string


Using monger, I am writing a document that contains a vector with a keyword item to a collection like

(monger.collection/insert-and-return db 
                                    "test-coll" {:_id 1 :some-vector [:a-keyword]})

which returns as expected

{:_id 1, :some-vector [:a-keyword]}

but then if I fetch the particular document like

(monger.collection/find-map-by-id db "test-coll" 1)

the keyword has been changed to a string

{:_id 1, :some-vector ["a-keyword"]}

Is that expected behaviour and if so why?


Solution

  • This is expected behaviour as the mongo database store doesn't support keywords; it is essentially json. http://clojuremongodb.info/articles/inserting.html#serialization_of_clojure_data_types_to_dbobject_and_dblist

    You will have to manually convert the values back to keywords using monger.conversion/from-db-object.