mongodbclojuremonger

Query mongo With joda.time.datetime using clojure-monger


I got this error code when tried query obj with {$lte start $gte end}, can u show me some sample of querying with coda.datetime?

IllegalArgumentException can't serialize class org.joda.time.DateTime org.bson.BasicBSONEncoder._putObjectField (BasicBSONEncoder.java:284)

The Func:

(defn data->orders [start end]
  (let [db (mg/get-db conn/mongo-db "db")
        coll "coll"
        formatter (f/formatter "YYYY-MM-dd")]
    (mc/find-maps db coll
                  {:created_at
                   {$gte (f/parse formatter start)
                    $lte (f/parse formatter end)}})))

Solution

  • Read http://clojuremongodb.info/articles/integration.html

    Add to ns

    (:require monger.joda-time)
    

    See source: https://github.com/michaelklishin/monger/blob/master/src/clojure/monger/joda_time.clj