Couchdb query multiple keys – How To

When you work with Couchdb. You want to get multiple keys from a view. Today I will show you how to do that. What you need is to create a post request. Then submit the keys.

Your HTTP request will look like this:

POST /your_db/_design/yourFilters_A/_view/getItemByForeignKeyId
Content-Type: application/json

{
   "keys" : [
      "AAA",
      "BBB"
   ]
}

Param:

  • keys (json-array) – Return only documents where the key matches one of the keys specified in the array.

 

Or trying to use key:

POST /your_db/_design/yourFilters_A/_view/getItemByForeignKeyId
Content-Type: application/json

{
   "key" : "ABC"
}

Param:

  • key (json) – Return only documents that match the specified key.

 

Structure for you to understand:

GET /{db}/_design/{ddoc}/_view/{view}

Parameters:
db – Database name
ddoc – Design document name
view – View function name

If you have any questions, please comment

Sponsored Links