Reputation: 16982
I am using Spring Data findAll(Iterable) method to retrieve info from couchbase. However I am seeing null response.
I defined the below listed repository :
public interface CustomerRepository extends CrudRepository<Customer, String> {
}
I am fetching the data by passing valid json
Iterable<Customer> custIter=customerRepository.findAll(customerList);
View is defined as below :
function (doc, meta) {
if(doc._class=="com.customer.model.types.Customer" ){
emit(meta.id, doc);
}
}
EDIT:
If I make a findOne call in a loop preceeding findAll call , findAll call returns data.
Upvotes: 1
Views: 2026
Reputation: 1823
A bit late, but I just had an issue because of @FuzzyAmi's remark. Don't emit (null, null)
, because the findAll(Iterable<ID>)
method relies on the KEYS and not on the ID to find the documents. I had a view emitting (null, null)
and findAll(Iterable<ID>)
always returned an empty list. I think this should be documented in spring-data-couchbase javadoc.
Emit (meta.id, null)
to be able to use spring-data-couchbase findAll(Iterable<ID>)
.
@simon-baslé: I think the documentation should be updated.
Upvotes: 2
Reputation: 28301
findAll being based on a view, I think this may be due to view indexation delay... Do you happen to recreate data just before you execute this code? IIRC no specific staleness criteria is used by this version so it should default to UPDATE_AFTER, which will resynchronize the index after the first query (which correspond to what you see with first findAll vs following ones...)
Upvotes: 1