I am new using Spring Data for Couchbase, I defined this object
public class Building {
@NotNull
@Id
private String id;
@NotNull
@Field
private String name;
@NotNull
@Field
private String companyId;
}
I want to count all the elements in the DB by Id, so I created this function:
@Repository
@N1qlPrimaryIndexed
@ViewIndexed(designDoc = "building")
public interface BuildingRepository extends CouchbaseRepository<Building, String> {
@Query("SELECT COUNT(*) AS count FROM #{#n1ql.bucket} WHERE #{#n1ql.filter} and id = $1")
Long countBuildings(String id);
}
but I am getting 0, just after the save an object
I also tried
@Query("#{#n1ql.selectEntity} WHERE #{#n1ql.filter} and id = $1")
Long countBuildings(String id);
but I got this Exception
org.springframework.data.couchbase.core.CouchbaseQueryExecutionException: Query returning a primitive type are expected to return exactly 1 result, got 0