Un altro modo per farlo utilizzando i modelli di query MongoRepository:
public interface MyRepository extends MongoRepository<MyClass, String> {
Long countByLastname(String lastname);
}
Vedi http://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#repositories.query-methods.details