9
votes

in Couchbase DB, is it possible to retrieve multiple documents using key prefix as query string, and it returns all the key-values which has key starting with supplied key prefix (like operator kind of thing)? without using Views or queries/indices.

I am designing my keys the way it is shown in Slide 51 of this presentation http://www.slideshare.net/Couchbase/couchbase-103-data-modeling

1
Is there a reason why you don't wish to use a view for this? Keep in mind that you can have the view or query only tell you the actualy IDs you need to fetch, and then you would fetch those using the normal KV APIs - Mark Nunberg

1 Answers

13
votes

If you don't want to use a view or n1ql query, there is no way to retrieve documents without knowing their exact keys. That is, you can only retrieve your prefix-based keys if you have a way to generate the possible keys on the client side in advance, e.g. User-1, User-2 ... User-n.

You can, however, do the sort of prefix query you're talking about in n1ql without creating any additional indexes, because with n1ql you will already have a primary index on all the document keys. So you can do something like "SELECT META(myBucket).id FROM myBucket WHERE META(myBucket).id LIKE "prefix%";