couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robertkowal...@apache.org
Subject [39/50] [abbrv] couchdb-mango git commit: Fix queries that include {"$exists": false}
Date Tue, 03 Feb 2015 15:13:46 GMT
Fix queries that include {"$exists": false}

We were incorrectly stripping documents for which a field didn't exist.

BugzId: 33294


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

Branch: refs/heads/master
Commit: bb91429c143d79e7c9a053233852ec2600ea23a0
Parents: 8f3b355
Author: Paul J. Davis <paul.joseph.davis@gmail.com>
Authored: Fri Jan 9 16:08:58 2015 -0600
Committer: Paul J. Davis <paul.joseph.davis@gmail.com>
Committed: Fri Jan 16 13:32:50 2015 -0600

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


http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/bb91429c/src/mango_selector.erl
----------------------------------------------------------------------
diff --git a/src/mango_selector.erl b/src/mango_selector.erl
index 4da394d..56f2072 100644
--- a/src/mango_selector.erl
+++ b/src/mango_selector.erl
@@ -501,6 +501,8 @@ match({[{<<"$", _/binary>>=Op, _}]}, _, _) ->
 % bad_path in which case matching fails.
 match({[{Field, Cond}]}, Value, Cmp) ->
     case mango_doc:get_field(Value, Field) of
+        not_found when Cond == {[{<<"$exists">>, false}]} ->
+            true;
         not_found ->
             false;
         bad_path ->

http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/bb91429c/test/03-operator-test.py
----------------------------------------------------------------------
diff --git a/test/03-operator-test.py b/test/03-operator-test.py
index 27418a6..d8a7c29 100644
--- a/test/03-operator-test.py
+++ b/test/03-operator-test.py
@@ -80,3 +80,13 @@ class OperatorTests(mango.UserDocsTests):
         assert len(docs) == 2
         assert docs[0]["user_id"] == 2
         assert docs[1]["user_id"] == 10
+
+    def test_exists_false(self):
+        docs = self.db.find({
+                "age": {"$gt": 0},
+                "twitter": {"$exists": False}
+            })
+        user_ids = [2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 14]
+        assert len(docs) == len(user_ids)
+        for doc in docs:
+            assert doc["user_id"] in user_ids


Mime
View raw message