How to use CouchDB username in URL rewriting?
I have a list function that can be accessed like this:
_list/characters/characters_by_user?startkey=["org.couchdb.user:rodriguez"]&endkey=["org.couchdb.user:rodriguez", {}]
I am trying to rewrite the url so you can access it in a friendlier way ...
/rodriguez/characters
... by writing this rule:
{from: '/:user/characters', to: '_list/characters/characters_by_user',
query: {
startkey: "[%22org.couchdb.user%3A:user%22]",
endkey: "[%22org.couchdb.user%3A:user%22,%20{}]"
}
}
However, I am getting this error:
error: "query_parse_error",
reason: "No rows can match your key range, reverse your start_key and end_key or set descending=true"
Why does the request work correctly in the full url but doesn't use rewriting?
Update
I believe this may be a bug with the way CouchDB handles the encoded colon (% 3A). I am awaiting an answer from the mailing list and will update this question accordingly.
+3
source to share
1 answer
I found that checking the CouchDB logs proved to be the best way to troubleshoot URL rewriting issues. Unfortunately, the question I posted on the CouchDB mailing list hasn't been answered yet.
As a workaround, I chose a username without its full qualifications, which suits my goal:
var user = doc.createdBy.split(":")[1];
emit(user, doc);
0
source to share