Skip to content
Snippets Groups Projects
Commit ea1245ba authored by Cam Saül's avatar Cam Saül
Browse files

Support Date() calls in MongoDB native queries

parent adb1efe0
Branches
Tags
No related merge requests found
......@@ -381,12 +381,19 @@
;; 2) Parse Normally
;; 3) Walk the parsed JSON and convert forms like [:___ISODate ...] to JodaTime dates, and [:___ObjectId ...] to BSON IDs
;; add more fn handlers here as needed
;; See https://docs.mongodb.com/manual/core/shell-types/ for a list of different supported types
(def ^:private fn-name->decoder
{:ISODate (fn [arg]
(DateTime. arg))
:ObjectId (fn [^String arg]
(ObjectId. arg))})
{:ISODate (fn [arg]
(DateTime. arg))
:ObjectId (fn [^String arg]
(ObjectId. arg))
:Date (fn [& _] ; it looks like Date() just ignores any arguments
(u/format-date "EEE MMM dd yyyy HH:mm:ss z")) ; return a date string formatted the same way the mongo console does
:NumberLong (fn [^String s]
(Long/parseLong s))
:NumberInt (fn [^String s]
(Integer/parseInt s))})
;; we're missing NumberDecimal but not sure how that's supposed to be converted to a Java type
(defn- form->encoded-fn-name
"If FORM is an encoded fn call form return the key representing the fn call that was encoded.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment