couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tonysu...@apache.org
Subject couchdb-mango git commit: Fix $nin operator
Date Wed, 07 Oct 2015 20:08:32 GMT
Repository: couchdb-mango
Updated Branches:
  refs/heads/2844-fix-nin 06cf106dc -> 0dd2000f6


Fix $nin operator

This fixes $nin when the field is an array.

BugzID:44528


Project: http://git-wip-us.apache.org/repos/asf/couchdb-mango/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-mango/commit/0dd2000f
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-mango/tree/0dd2000f
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-mango/diff/0dd2000f

Branch: refs/heads/2844-fix-nin
Commit: 0dd2000f666e49204b0429a81f660de237aaeccf
Parents: 06cf106
Author: Tony Sun <tony.sun@cloudant.com>
Authored: Wed Oct 7 13:07:58 2015 -0700
Committer: Tony Sun <tony.sun@cloudant.com>
Committed: Wed Oct 7 13:07:58 2015 -0700

----------------------------------------------------------------------
 src/mango_selector.erl   |  2 ++
 test/03-operator-test.py | 11 +++++++++++
 2 files changed, 13 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/0dd2000f/src/mango_selector.erl
----------------------------------------------------------------------
diff --git a/src/mango_selector.erl b/src/mango_selector.erl
index 21c55ae..c6004cd 100644
--- a/src/mango_selector.erl
+++ b/src/mango_selector.erl
@@ -471,6 +471,8 @@ match({[{<<"$in">>, Args}]}, Value, Cmp) ->
     Pred = fun(Arg) -> Cmp(Value, Arg) == 0 end,
     lists:any(Pred, Args);
 
+match({[{<<"$nin">>, Args}]}, Values, Cmp) when is_list(Values)->
+    not match({[{<<"$in">>, Args}]}, Values, Cmp);
 match({[{<<"$nin">>, Args}]}, Value, Cmp) ->
     Pred = fun(Arg) -> Cmp(Value, Arg) /= 0 end,
     lists:all(Pred, Args);

http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/0dd2000f/test/03-operator-test.py
----------------------------------------------------------------------
diff --git a/test/03-operator-test.py b/test/03-operator-test.py
index d8a7c29..50d5bd2 100644
--- a/test/03-operator-test.py
+++ b/test/03-operator-test.py
@@ -72,6 +72,17 @@ class OperatorTests(mango.UserDocsTests):
         assert docs[0]["user_id"] == 2
         assert docs[1]["user_id"] == 12
 
+    def test_nin_operator_array(self):
+        docs = self.db.find({
+                "manager": True,
+                "favorites": {"$nin": ["Erlang", "Python"]}
+            })
+        assert len(docs) == 4
+        for doc in docs:
+            if isinstance(doc["favorites"], list):
+                assert "Erlang" not in doc["favorites"]
+                assert "Python" not in doc["favorites"]
+
     def test_regex(self):
         docs = self.db.find({
                 "age": {"$gt": 40},


Mime
View raw message