diff --git a/src/clojure/monger/operators.clj b/src/clojure/monger/operators.clj index 6a9abc1..53e501b 100644 --- a/src/clojure/monger/operators.clj +++ b/src/clojure/monger/operators.clj @@ -96,6 +96,13 @@ (defoperator $regex) (defoperator $options) +;; Matches documents that satisfy a JavaScript expression. +;; +;; EXAMPLES: +;; +;; (monger.collection/find "people" { $where "this.placeOfBirth === this.address.city" }) +(defoperator $where) + ;; ;; LOGIC OPERATORS ;; diff --git a/test/monger/test/query_operators_test.clj b/test/monger/test/query_operators_test.clj index 5022e04..1cc6184 100644 --- a/test/monger/test/query_operators_test.clj +++ b/test/monger/test/query_operators_test.clj @@ -125,4 +125,10 @@ {:language {$regex "clo.*" $options "i"}} 2 {:name {$regex "aK.*" $options "i"}} 1 {:language {$regex ".*by"}} 1 - {:language {$regex ".*ala.*"}} 1)))) + {:language {$regex ".*ala.*"}} 1))) + + (deftest find-with-js-expression + (let [collection "people"] + (mc/insert-batch db collection [{:name "Bob" :placeOfBirth "New York" :address {:city "New York"}} + {:name "Alice" :placeOfBirth "New York" :address {:city "Los Angeles"}}]) + (is (= 1 (.count (mc/find db collection {$where "this.placeOfBirth === this.address.city"})))))))