Skip to content

Simple Spring Data Couchbase Find Query Not Working

I’m new to Couchbase and Spring Data Couchbase and am having issues getting a simple find query to work. I am running the community edition of couchbase (version 6.6.0), have the latest version of Spring Data Couchbase, and have created a small spring boot app to query from a new bucket I created. I am able to connect to the database ok, but none of the find queries I am using return any data. I have gone into the bucket and added a few indexes, but that didn’t seem to help either. I am hoping it is just something small that I am missing.

Here is my code…


public class Config extends AbstractCouchbaseConfiguration {

    public String getConnectionString() {
        return "couchbase://";

    public String getUserName() {
        return "Administrator";

    public String getPassword() {
        return "admin1";

    public String getBucketName() {
        return "testing";

    protected boolean autoIndexCreation() {
        return true;


public class UserInfo {
    private String id;
    private String name;

    public String getId() {
        return id;

    public String getName() {
        return name;


public interface UserRepository extends CrudRepository<UserInfo, String> {
    List<UserInfo> findByName(String name);

Main code that runs on app startup. I never seem to be getting data back, even though I have a few documents in my bucket.

public class StartupConfig {
    public TravelRepository travelRepository;

    public UserRepository userRepository;

    public void postConstruct() {
        System.out.println("Processing data...");
        List<UserInfo> userInfo = userRepository.findByName("Steve");
        //List<NameInfo> nameInfo = nameRepository.findAll();
        if (userInfo.size() == 0) {
            System.out.println("No data found");
        } else {
            System.out.println("Data found: " + userInfo.get(0).getName());


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi=""
        <relativePath/> <!-- lookup parent from repository -->
    <description>Demo project for Spring Boot</description>






OK, I figured out the issue. I was manually inserting data via the Admin console, and I didn’t realize that you have to add an _class attribute to your documents. When Spring Data Couchbase generates its queries, they will look something like this:

Select * from testing where name = "Steve" and _class= "com.example.couchbase.model.UserInfo";

And it won’t find any data if the _class attribute is missing (unless there is some property setting or something that lets you get around this).

User contributions licensed under: CC BY-SA
7 People found this is helpful