Search code examples
spring-datacouchbasecouchbase-viewspring-data-couchbase

Simple "count()" query with Spring Data Couchbase


I'm having a problem I don't seem to find a solution for, and it looks really odd given i've tried everything I could with the official Spring Data Couchbase documentation.

Basically all i'm trying to do is a simple count() method.

My Repository :

public interface ICourrierRepository extends CrudRepository<Courrier, String> {

List<Courrier> findByCategorie(String categorie);

Long countByCategorie(String categorie);

@View(designDocument = "_design/courrier", viewName = "courrierBase")
long count();

}

The view is setup like this : http://img15.hostingpics.net/pics/169793Capture.png

And the view map is like this :

function (doc, meta) {
  if (doc._class == "com.model.Courrier") {
    emit(meta.id, null);
  }
}

Worst thing is it actually works when i set a "reduce" to "_count" in the CouchBase GUI, but when I launch it from my client, I always get the same message, and the return is 0 :

[cb-computations-2] INFO  c.c.c.java.view.ViewRetryHandler - Received a View HTTP response code (400) I did not expect, not retrying.

Thanks for any help...


Solution

  • I actually found the problem... it comes from this line :

    @View(designDocument = "_design/courrier", viewName = "courrierBase")
    

    which should be

    @View(designDocument = "courrier", viewName = "courrierBase")
    

    Also, the view should be set to reduce : _count.

    Hope this helps future users !