Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 266B5200C73 for ; Wed, 10 May 2017 08:35:10 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 24FD1160BB4; Wed, 10 May 2017 06:35:10 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 6BF62160BA8 for ; Wed, 10 May 2017 08:35:09 +0200 (CEST) Received: (qmail 42774 invoked by uid 500); 10 May 2017 06:35:08 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 42765 invoked by uid 99); 10 May 2017 06:35:08 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 May 2017 06:35:08 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 50FB1812D2; Wed, 10 May 2017 06:35:07 +0000 (UTC) Date: Wed, 10 May 2017 06:35:07 +0000 To: "commits@couchdb.apache.org" Subject: [couchdb] branch master updated: Mango $allMatch return false for empty list (#511) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <149439810705.3402.7971722423690376959@gitbox.apache.org> From: garren@apache.org Reply-To: "commits@couchdb.apache.org" X-Git-Host: gitbox.apache.org X-Git-Repo: couchdb X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 84b38f82d5e3bd176f0dc2c6ba1226db0669b19b X-Git-Newrev: 0460a70d1499d805388fc14edcc4e1e7c57e0be4 X-Git-Rev: 0460a70d1499d805388fc14edcc4e1e7c57e0be4 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.3.dev Auto-Submitted: auto-generated archived-at: Wed, 10 May 2017 06:35:10 -0000 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 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" '].