Finding design docs

Is it possible to run a query in CBL that will return all the design docs in the db?

Run an all-docs query with startKey="_design/" and endKey="_design/\uffffffff". Or (iOS/Mac only) instead of setting endKey set prefixMatchLevel=1 (in the REST API it’s called prefix_match_level.)

2 Likes

Tried both but I’m getting every document in the database returned.

What does your code look like?

I’m using the rest API and called GET at this url:

http://lite.couchbase./my_db/_all_docs?startKey=%22_design%2F%22&endKey=%22_design%2F%EF%BF%BFffff%22

Perhaps the escaping of the end key isn’t working? My code has 8 fs but when i print the url out it looks like there’s only 4

Ugh, that’s got UTF-8 being URL-escaped. I think you’ll need to use a JSON Unicode escape, i.e. literally have \u in the JSON:

http://lite.couchbase./my_db/_all_docs?startKey=%22_design%2F%22&endKey=%22_design%2F%5CuFFFFFFFF%22

Or it’s simpler with prefix-matching:

http://lite.couchbase./my_db/_all_docs?startKey=%22_design%2F%22&prefix_match_level=1

Hmm, http://lite.couchbase./my_db/_all_docs?startKey=%22_design%2F%22&prefix_match_level=1 still returns all 11000+ rows in the db.

Ah, got it — it should be startkey not startKey.

This is super weird, now I’m getting fewer words back (but still thousands) using:

.../_all_docs?startkey=%22_design%2F%22&prefix_match_level=1

I tried the other method, but fixed the escaping (my bad!)

.../_all_docs?startkey=%22_design%2F%22&endkey=%22_design%2F%EF%BF%BF%22

Which seems to work.

Thanks