0

I am working on the Apache CouchDB using the cURL. I have created a database added database files & created a view. I have made the following configurations for mapping the keys to the view.

function (doc) { emit([doc.key1, doc.key2, doc.key3], doc); } 

I would like to access the database file using a combination of keys. i.e. In the above case, key1 is fixed in my URL's get request. but I don't have control over key2 & key3(sometimes I have key2 & rest I have key3).

Will you please help me to know, How can I access the database with a combination of key1-key2 OR key1-key3?

1
  • Will a document ever have both key2 and key3? Is it important to differentiate the two keys in a query? Commented Aug 5, 2021 at 13:21

2 Answers 2

0

Have a look at this Guide with compound keys: https://docs.couchdb.org/en/stable/ddocs/views/collation.html#examples

Thus, you could try something like this:

startkey=[<val_key1>]&endkey[<val_key1>,{}] 

or

startkey=[<val_key1>,<val_key2>]&endkey[<val_key1>,<val_key2>,{}] 

If you use cURL, don't forget to encode the curly brackets or use option -g/--globoff (Passing a URL with brackets to curl).

EDIT:

Sign up to request clarification or add additional context in comments.

Comments

0

How can I access the database with a combination of key1-key2 OR key1-key3?

If you want to access documents based on the existence or value of key1, key2, key3, you most likely don't want to create a View that simply emits all them as keys.

Instead, first have a look at Mango queries using the _find-API and construct them s.t. the desired documents are returned. For example:

{ "selector": { "key1": { "$gt": null }, "key2" { "$lt": "too high" } } 

The, create a matching index or view for your queries.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.