Search code examples
spring-datacouchbasekotlin-flowsql++spring-data-couchbase

Spring in Kotlin: Getting data from couchbase server using special query brings back an empty object


I have a Spring micro-service that has been working for months now. The owner wanted to add 2 additional function, one of them required a custom query:

SELECT Meta().id AS __id, *
FROM `bucket`
WHERE _class = "com.....CurrencyDominationDao"
AND lastUpdated >= $1 AND storeId = $2"

The query works well inside couchbase query section online, it retrieve the data as needed. but when I use it from spring, I get an empty Dao object, only the document ID that is in it. The same Dao object is used for other queries and is getting the data correctly. I request the data from the repository using service layer,the data that is coming from the repository is empty, it matches the Dao object default values.

I checked the query logs in couchbase, it is successful. no errors whatsoever.

only when it comes to this query, I get an empty Dao object with the document Id.

I tested the query several times. each time it brings back the right number of data objects it should get from the database, but all of them are empty.

I use reactive structure, using coroutines flow.

how is that possible? how can I solve it?


Solution

  • Use the built-in variable for the SELECT ... part of your query. And also for the predicate on _class...

    @Query("#{#n1ql.selectEntity} WHERE #{#n1ql.filter} AND iata != $1")
    List<Airport> getAllByIataNot(String iata, Pageable pageable);