couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gar...@apache.org
Subject [couchdb] branch master updated: Mango $allMatch return false for empty list (#511)
Date Wed, 10 May 2017 06:35:07 GMT
This is an automated email from the ASF dual-hosted git repository.

garren pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb.git

The following commit(s) were added to refs/heads/master by this push:
       new  0460a70   Mango $allMatch return false for empty list (#511)
0460a70 is described below

commit 0460a70d1499d805388fc14edcc4e1e7c57e0be4
Author: garren smith <garren.smith@gmail.com>
AuthorDate: Wed May 10 08:35:04 2017 +0200

    Mango $allMatch return false for empty list (#511)
    
    The $allMatch selector returns false for a document with an empty list
---
 src/mango/src/mango_selector.erl   |  2 +-
 src/mango/test/03-operator-test.py | 18 +++++++++++++++---
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/mango/src/mango_selector.erl b/src/mango/src/mango_selector.erl
index 691aac7..13e7d88 100644
--- a/src/mango/src/mango_selector.erl
+++ b/src/mango/src/mango_selector.erl
@@ -461,7 +461,7 @@ match({[{<<"$elemMatch">>, _Arg}]}, _Value, _Cmp) ->
 
 % Matches when all elements in values match the
 % sub-selector Arg.
-match({[{<<"$allMatch">>, Arg}]}, Values, Cmp) when is_list(Values) ->
+match({[{<<"$allMatch">>, Arg}]}, Values, Cmp) when is_list(Values), length(Values)
> 0 ->
     try
         lists:foreach(fun(V) ->
             case match(Arg, V, Cmp) of
diff --git a/src/mango/test/03-operator-test.py b/src/mango/test/03-operator-test.py
index 56c2862..edfd95f 100644
--- a/src/mango/test/03-operator-test.py
+++ b/src/mango/test/03-operator-test.py
@@ -20,7 +20,6 @@ class OperatorTests(mango.UserDocsTests):
                 "manager": True,
                 "favorites": {"$all": ["Lisp", "Python"]}
             })
-        print docs
         assert len(docs) == 4
         assert docs[0]["user_id"] == 2
         assert docs[1]["user_id"] == 12
@@ -59,7 +58,6 @@ class OperatorTests(mango.UserDocsTests):
                 "bam": True
             }}
         })
-        print docs
         assert len(docs) == 1
         assert docs[0]["user_id"] == "b"
 
@@ -94,7 +92,6 @@ class OperatorTests(mango.UserDocsTests):
         ]
         self.db.save_docs(amdocs, w=3)
         docs = self.db.find({
-            "_id": {"$gt": None},
             "bang": {"$allMatch": {
                 "foo": {"$mod": [2,1]},
                 "bar": {"$mod": [2,0]}
@@ -102,6 +99,21 @@ class OperatorTests(mango.UserDocsTests):
         })
         assert len(docs) == 1
         assert docs[0]["user_id"] == "a"
+    
+    def test_empty_all_match(self):
+        amdocs = [
+            {
+                "bad_doc": "a",
+                "emptybang": []
+            }
+        ]
+        self.db.save_docs(amdocs, w=3)
+        docs = self.db.find({
+            "emptybang": {"$allMatch": {
+                "foo": {"$eq": 2}
+            }}
+        })
+        assert len(docs) == 0
 
     def test_in_operator_array(self):
         docs = self.db.find({

-- 
To stop receiving notification emails like this one, please contact
['"commits@couchdb.apache.org" <commits@couchdb.apache.org>'].

Mime
View raw message