I've tried reading the CouchDB documentation, but I find it a bit vague in this area (FAUXTON, vhost specification). I've searched and read the responses on stackoverflow for "couchdb vhosts" and "couchdb rewrite url" and tried to apply the advice I can gleen there. Still stuck on this and would appreciate some specific direction if anyone can provide it.
I have around 1900 documents in a couchDB database. Each document has a "type" key. I've made 30 design documents, one per "type". Each design docuemnt has a view called "all" that returns all rows of the document of that type.
In the information below, dasvm01.com is not the actual server. It is behind a company firewall and not accessible to the outside world. I've tried to use it consistently, forgive me if I have errored anywhere.
So, now I can execute a GET like this from a browser:
dasvm01.com:5984/registryservice/_design/airplaneidtypes/_view/all
My immediate goal is to shorten this to:
dasvm01.com:5984/registryservice/airplaneidtypes
or
dasvm01.com:5984/registryservice/airplaneidtypes/all
To this end, I added a rewrites function to the airplaneidtypes design doc:
{
"_id": "_design/airplaneidtypes",
"_rev": "11-c28b41a718017cbcd65f82f4acc611cb",
"views": {
"all": {
"map": "function (doc)
{ if(doc.ddoc === 'airplaneidtypes')
{ emit(doc._rev,doc); }
}"
}
},
"language": "javascript",
"rewrites": [
{
"from": "/airplaneidtypes",
"to": "registryservice/_design/airplaneidtypes/_rewrite",
"method": "GET"
}
]
}
Now I think that I need to update the CouchDB daemon:vhosts setting: I took a crack at it, but I really had no level of confidence and it doesn't seem to work. In Fauxton, I have:
daemons
auth_cache {couch_auth_cache, start_link, []}
...
vhosts {dasvm01.com:5984, /registryservice/_design/airplaneidtypes/_rewrite, []}
Not sure if this is: - close, - way off, - not the correct place, - just needs quotes...
What can you tell me? I don't understand default the notation in Fauxton is trying to convey:
vhosts
Virtual hosts manager. Provides dynamic add of vhosts without restart, wildcards support and dynamic routing via pattern matching
[daemons]
vhosts={couch_httpd_vhost, start_link, []}
Ultimately, I want/hope to allow the user to pass multiple key:value pairs on the URL and then rewrite them into a MANGO query. The user would pass something like this:
dasvm01.com:5984/registryservice/airplaneidtypes/model/A320/variant/251N
that would get rewritten into the MANGO query:
{
"selector": {
"model": "A320",
"variant": {"$eq": "251N"}
},
"fields": [
"_id",
"_rev",
"status",
"model",
"variant",
"variant-type",
"oem",
"historicaloem",
"displaymodel",
"actsmodel"
]
}