You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2018/12/04 14:14:06 UTC

[GitHub] willholley commented on a change in pull request #1719: Don't use $not to validate use of index

willholley commented on a change in pull request #1719: Don't use $not to validate use of index
URL: https://github.com/apache/couchdb/pull/1719#discussion_r238677587
 
 

 ##########
 File path: src/mango/test/03-operator-test.py
 ##########
 @@ -251,6 +251,16 @@ def test_gte_respsects_unicode_collation(self):
             })
         user_ids = [12,13,14]
         self.assertUserIds(user_ids, docs)
+
+    def test_ne_returns_correct_docs(self):
+        selector = {
+            "twitter": {
+                "$ne": "@nonahorton"
+            }
+        }
+        docs = self.db.find(selector, fields=["user_id"])
+        ex = self.db.find(selector, fields=["user_id"], explain=True)
+        self.assertUserIds([0,1,9,13], docs)
 
 Review comment:
   We probably want to exercise `$not` here (even though it may be normalized to `$ne` under the hood). For example:
   ```
   # gotcha here is that this implicitly adds { $exists: true } for the referenced field,
   # so is not strictly the inverse of { "ordered":"A" }
   def test_not_returns_expected_docs(self):
           selector = {
               "$not": {
                   "ordered": "A"
               }
           }
           docs = self.db.find(selector, fields=["user_id"])
           ex = self.db.find(selector, fields=["user_id"], explain=True)
   
           # returns all docs that have an "ordered" field that is not equal to "A"
           self.assertUserIds([6, 7, 8, 9, 10, 11, 12, 14], docs)
   ```
   
   as mentioned in the test, there is an underlying oddity/bug in Mango where we differ from MongoDB behaviour for $not and $ne operators. [MongoDB docs](https://docs.mongodb.com/manual/reference/operator/query/not/) state:
   > $not performs a logical NOT operation on the specified <operator-expression> and selects the documents that do not match the <operator-expression>. This includes documents that do not contain the field.
   
   Mango will currently only return documents that contain the field; to return documents that do not contain the field, the user needs to add an explicit `$exists: false` to the selector. I think this is incorrect but it's a tricky thing to change at this point; perhaps @davisp can remember why it is this way?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services