Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Couchbase - retrieving multiple documents using key prefix

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

like image 422
Anand Avatar asked Jun 01 '15 12:06

Anand


1 Answers

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%";

like image 137
David Ostrovsky Avatar answered Nov 16 '22 01:11

David Ostrovsky