Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Key value doesn't work as json, only as string #5396

Open
Pragrammist opened this issue Jan 12, 2025 · 3 comments
Open

Key value doesn't work as json, only as string #5396

Pragrammist opened this issue Jan 12, 2025 · 3 comments

Comments

@Pragrammist
Copy link

Description

When you pass "key" query to GET /{db}/_design/{ddoc}/_view/{view}
for example /your_db/_design/your_doc/_view/some_view?key="some_exist_key" works fine, it return rows if it match.
But if you use json as key: /your_db/_design/your_doc/_view/some_view?key={"json_example": "some_exist_key"} for example will not return any row even if {"json_example": "some_exist_key"} as key exist.

Steps to Reproduce

I use it

http://admin:admin@localhost:5984/account_documents/_design/unique_data_design_doc/_view/account_id_rev_by_hash_password_login?key={"login": "login_2","password_hash": "XKJyibT/PjDRPy2X/DP86v12ZmzKdHuVudId5E0+4ts"}

with view

function (doc) {
  emit({login:doc.login, password_hash:doc.password_hash}, [doc._id, doc._rev]);
}

If you want reproduce bag, just add document and then view with json as key and then try retrieve by then key row, you got empty row array

Expected Behaviour

Possibility to retrieve document by json not only by string, so key like

{"login": "login_2","password_hash": "XKJyibT/PjDRPy2X/DP86v12ZmzKdHuVudId5E0+4ts"} 

will return not empty array rows if key is exists

Your Environment

I think it's not matter
TIP: # ( Include as many relevant details about your environment as possible. )
TIP: # ( You can paste the output of curl http://YOUR-COUCHDB:5984/ here. )

  • CouchDB version used: 3.4.2
  • Browser name and version: edge, postman
  • Operating system and version: windows 10

Additional Context

@janl
Copy link
Member

janl commented Jan 14, 2025

This is not functionality that CouchDB supports. What made you think this would work? I misread the question, apologies.

@Pragrammist
Copy link
Author

Pragrammist commented Jan 15, 2025

Well, startkey and endkey support json as value. And, important, if you read couchdb doc you see key is json, not a string.

https://docs.couchdb.org/en/stable/api/ddoc/views.html

And if it's not a json, why there's it's described as json, not a string.
I spent several hours because of that
Did you read couchdb doc?!

@rnewson
Copy link
Member

rnewson commented Jan 15, 2025

hm, odd. I definitely expect exact lookup to work for a key that is a json object. It worked for me locally and is definitely intentionally supported. The collation specification even details the ordering that we apply for json objects (https://docs.couchdb.org/en/stable/ddocs/views/collation.html#collation-specification).

Now, note that you would have to match the key, you couldn't find a row with key of {"foo":"bar", "bar":"baz"} with just ?key={"foo":"bar"}.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants