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?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
shiv patil
  • 99
  • 1
  • 1
  • 6

2 Answers2

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.

LyteFM
  • 895
  • 8
  • 12
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:

Rea
  • 16
  • 1