3

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'm attempting 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 get 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 would the query work correctly in the full URL, but not using the rewrite?


Update

I believe this may be a bug with the way CouchDB handles the encoded colon (%3A). I'm awaiting a response from the mailing list and will update this question accordingly.

Matt Norris
  • 8,596
  • 14
  • 59
  • 90
  • Hmmm...I'll do my best to help diagnose, but I'm not certain on an answer. It's very possible that there's an error in the rewrite, and whatever it's actually rewriting to yields that error you're seeing. That being said, why is there a colon in here "{from: '/:user/characters'". Also, have you tried taking out those %2f's? Are you running this on CouchDB 1.2? – Costa Michailidis Apr 07 '12 at 22:14
  • Also, maybe just try ?key="org.couchdb.user:rodriguez" – Costa Michailidis Apr 07 '12 at 22:17
  • I agree, It certainly seems like there's an error on the rewrite. How do I see what it rewrites to? Is there something on Chrome developer tools or a way to output it to the console? The colon is there to represent a variable, as noted here http://wiki.apache.org/couchdb/Rewriting_urls. I have tried with and without the URL-encoding, and receive the same result (though I do HAVE to use encoding to represent the colon in org.couchdb.user:username because I cannot escape it in the string). I am using CouchDB 1.1.1. – Matt Norris Apr 09 '12 at 01:24
  • Hmmm...if you haven't already found this, it might be helpful to you: http://blog.couchbase.com/what%E2%80%99s-new-apache-couchdb-011-%E2%80%94-part-one-nice-urls-rewrite-rules-and-virtual-hosts It goes into a little more detail on how to do rewrites with variables. – Costa Michailidis Apr 10 '12 at 04:55

1 Answers1

0

I found that checking CouchDB's logs proved to be the best way to troubleshoot how URLs were being rewritten. Unfortunately, the issue I submitted to the CouchDB mailing list has yet to be replied to.

As a workaround, I've emitted the user's name without fully-qualifying it, which suits my purpose:

var user = doc.createdBy.split(":")[1];
emit(user, doc);
Matt Norris
  • 8,596
  • 14
  • 59
  • 90