Question

First, this question - filter design documents from all_docs - already seemed to be solved like described here: https://plus.google.com/+JasonDeRose/posts/1iP5tu3wVqw

/mydb/_all_docs?endkey=%22_%22

and worked in first place. However, suddenly in a different setup (actually just different deploy), the query only returns an empty collection []. It seems like the ordering changed, without endkey="_" the full collection is returned (including design documents). I tried various combinations of endkey/startkey but cannot achieve to filter the design documents again.

Finally I added a filter and switched to _changes?include_docs=true to load the initial documents. I also thought about defining a view, but don't like that this results in data replication and some inconveniences with the changes feed (needed in another context). The filter on the other hand will be executed for every document.

Is it a bug that endkey=%22_%22 doesn't work anymore and is there a more convenient, still working way?

Was it helpful?

Solution

/_all_docs is a special case for CouchDB. Instead of the normal Unicode Collation, it uses ASCII collation.

The '_' character in ASCII order shows up between uppercase letters and lowercase letters. So if your doc id starts with lowercase letters (default behaviour), they will show up after any design docs. If your doc ids start with uppercase letters, they will show up before design docs.

Try creating a document with an id of: "ABC" You will see it show up before the design doc and your trick to filter design docs would work in this case.

However, I recommend you stop using the `_all_docs view altogether. Instead use the normal view functionality. When you create a view, CouchDB automatically skips design docs for you. So if your view looked like:

function(doc){
  emit(doc._id, null);
}

You could query this with no start or end key, and get all docs without design docs.

Also, please look at Unicode Collation order, this is the order all your other views will be in, and it's important to understand as you work with CouchDB. You can read all about it here:

http://docs.couchdb.org/en/stable/ddocs/views/collation.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top