I am using CouchDB v3.1.0 and am trying to create a selector for /{db}/_find
to find documents named "foobar".
In the docs section 1.3.6.1.1 Selector Basics
, there are several mentions of a $title
:
"selector": { "$title": "Live And Let Die" }
However, when I try to use it like so:
curl -X POST -H "Content-Type: application/json" \
http://my-host-machine:5984/testdb/_find \
-d '{"selector":{"$title":"foobar"}}' --user admin | jq .
The following error message is output:
{
"error": "invalid_operator",
"reason": "Invalid operator: $title"
}
What does work is using the _id
field in the selector: '{"selector":{"_id":"foobar"}}'
However, this doesn't feel correct to use a document's unique identifier. My questions:
- Does
$title
work? (Am I just using it incorrectly) - Is
_id
an appropriate method?
If a name field has a dollar sign (
$
) prefix, CouchDB interprets it as an operator.$title
however isn't a valid operator and the relatedselector
samples in the documentation seem to be wrong.On the other hand, when you need to select documents by a field that is preceded by a dollar sign (
$
), this answer may be useful.