couchbasesql++spring-data-couchbase

Couchbase Spring Data returns objects by ID without an index, but the Couchbase Query UI will not


I have a super simple Couchbase-Spring-Data project hooked up to a Couchbase 6.6 instance, based on the walkthrough from bealdung

The project works as expected and I'm able to create and read documents by ID from Couchbase. However, when I go to the couchbase UI and run a simple query;

select *, meta().id from `bucket` where meta().id = 'id:13'

(This is really what the ID looks like for now anyway).

The UI tells me No index available on keyspace bucket that matches your query. Which is true, there is no primary index or a dedicated index on meta().id.

So how is Couchbase-spring-data finding the objects?

I am still working my way down the documentation. But so far I've not found anything that clears the situation up.


Solution

  • For the most part, SQL++ queries need an index to run, so you are right to question what's going on.

    However, not every query needs an index. For instance, if I know the key, I can use the USE KEYS syntax in a SQL++ query:

    SELECT m.*, meta().id
    FROM `travel-sample`.myscope.mycollection m
    USE KEYS 'doc1'
    

    Note the predicate is USE KEYS 'doc1' instead of WHERE META().id = 'doc1'.

    I can't say for sure how Spring does it, it may use the key/value API when it can instead of SQL++ (which is the more efficient way to look data up if you already know the key).