summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgarren smith <garren.smith@gmail.com>2017-05-10 08:35:04 +0200
committerGitHub <noreply@github.com>2017-05-10 08:35:04 +0200
commit0460a70d1499d805388fc14edcc4e1e7c57e0be4 (patch)
tree3815c640fcf0c5407f803aa3870c1e2bd0bc9259
parent84b38f82d5e3bd176f0dc2c6ba1226db0669b19b (diff)
downloadcouchdb-0460a70d1499d805388fc14edcc4e1e7c57e0be4.tar.gz
Mango $allMatch return false for empty list (#511)
The $allMatch selector returns false for a document with an empty list
-rw-r--r--src/mango/src/mango_selector.erl2
-rw-r--r--src/mango/test/03-operator-test.py18
2 files changed, 16 insertions, 4 deletions
diff --git a/src/mango/src/mango_selector.erl b/src/mango/src/mango_selector.erl
index 691aac7ed..13e7d883b 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 56c286227..edfd95f4d 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({