Skip to content

Commit

Permalink
Add $where operator
Browse files Browse the repository at this point in the history
  • Loading branch information
jokimaki committed Oct 30, 2016
1 parent 08ce1e4 commit 8fd4946
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/clojure/monger/operators.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
;;
Expand Down
8 changes: 7 additions & 1 deletion test/monger/test/query_operators_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"})))))))

0 comments on commit 8fd4946

Please sign in to comment.