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

Don't add extra comma to fn calls with no args in Mongo native queries

parent b60b4a8d
Branches
Tags
No related merge requests found
......@@ -422,9 +422,11 @@
(encode-fncalls-for-fn \"ObjectId\" \"{\\\"$match\\\":ObjectId(\\\"583327789137b2700a1621fb\\\")}\")
;; -> \"{\\\"$match\\\":[\\\"___ObjectId\\\", \\\"583327789137b2700a1621fb\\\"]}\""
[fn-name query-string]
(s/replace query-string
(re-pattern (format "%s\\(([^)]*)\\)" (name fn-name)))
(format "[\"___%s\", $1]" (name fn-name))))
(-> query-string
;; replace any forms WITH NO args like ISODate() with ones like ["___ISODate"]
(s/replace (re-pattern (format "%s\\(\\)" (name fn-name))) (format "[\"___%s\"]" (name fn-name)))
;; now replace any forms WITH args like ISODate("2016-01-01") with ones like ["___ISODate", "2016-01-01"]
(s/replace (re-pattern (format "%s\\(([^)]*)\\)" (name fn-name))) (format "[\"___%s\", $1]" (name fn-name)))))
(defn- encode-fncalls
"Replace occurances of `ISODate(...)` and similary function calls (invalid JSON, but legal in Mongo)
......
......@@ -189,6 +189,11 @@
"[{\"$match\":{\"entityId\":{\"$eq\":[\"___ObjectId\", \"583327789137b2700a1621fb\"]}}}]"
(encode-fncalls "[{\"$match\":{\"entityId\":{\"$eq\":ObjectId(\"583327789137b2700a1621fb\")}}}]"))
;; make sure fn calls with no arguments work as well (#4996)
(expect
"[{\"$match\":{\"date\":{\"$eq\":[\"___ISODate\"]}}}]"
(encode-fncalls "[{\"$match\":{\"date\":{\"$eq\":ISODate()}}}]"))
(expect
(DateTime. "2012-01-01")
(maybe-decode-fncall ["___ISODate" "2012-01-01"]))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment