You will not be able to query the database using ..?testdata&key="countryname".
To query the database to get all documents where key="countryname"
, you will have to first create a view
in the database. See the CouchDB documentation at http://docs.couchdb.org/en/1.6.1/couchapp/views/intro.html.
I have provided an example below, if it helps:
Suppose your database contains the following documents:
{
"_id": "708ae78bd79fa9802c827e03d3000fe3",
"_rev": "1-f3408ffe54a9b9156dca5c9ad56ce396",
"name": "AFGHANISTAN",
"code": "AF"
}
{
"_id": "708ae78bd79fa9802c827e03d3001767",
"_rev": "1-9952b25ea39460b9923de505945efe3a",
"name": "ALAND ISLANDS",
"code": "AX"
}
{
"_id": "708ae78bd79fa9802c827e03d30030a5",
"_rev": "1-c1f3c9b2310f07f2985aa3fa363a281f",
"name": "ALBANIA",
"code": "AL"
}
Create a design document "_design/countries"
with a view "country"
in the database.
{
"_id": "_design/countries",
"_rev": "1-b30408713ded172df62502b45c959563",
"views": {
"country": {
"map": "function(doc) {\n emit(doc.name, null);\n}"
}
},
"language": "javascript"
}
You can now query the database like this: http://127.0.0.1:5984/countries/_design/countries/_view/country?key=%22ALBANIA%22&include_docs=true
This will return you the document for Albania.
{
"total_rows": 3,
"offset": 2,
"rows": [
{
"id": "708ae78bd79fa9802c827e03d30030a5",
"key": "ALBANIA",
"value": null,
"doc": {
"_id": "708ae78bd79fa9802c827e03d30030a5",
"_rev": "1-c1f3c9b2310f07f2985aa3fa363a281f",
"name": "ALBANIA",
"code": "AL"
}
}
]
}