go-kivik / kivik

Common interface to CouchDB or CouchDB-like databases for Go and GopherJS
Other
316 stars 44 forks source link

x/mango: Evaluation of `$exists: false` always fails #1043

Closed skaggmannen closed 2 months ago

skaggmannen commented 2 months ago

Bug Report Checklist (remove this template if submitting a feature request)

  1. Which version of Kivik are you using? Please state a version number, or master.

v4.3.1

  1. Which version of Go are you using? (Output of go version) -- Kivik 3.x supports Go 1.13 and later. Kivik 4.x requires Go 1.17 or later.

go version go1.23.0 darwin/arm64

  1. What did you do? (Include your code if possible)

I tried using the x/memorydb driver to speed up my tests, but ran into trouble with queries that checks for the non-existance of a field.

Given a document with the following structure:

{
  "_id": "some-doc-id",
  "_rev": "some-doc-rev",
  "foo": "bar"
}

The following query should match the document:

{
  "selector": {
    "baz": {
      "$exists": false
    }
  }
}
  1. What did you expect to see?

That the document was matched and returned when calling Find().

  1. What did you see instead?

The matching fails in fieldNode.Match() before it even reaches the $exists condition (selector.go:134):

val, ok := m[f.field]
if !ok {
    return false
}
return f.cond.Match(val)