Question

I am querying CouchBaseLite view but I am getting this exception every time I query it. It is not returning the result.

detailMessage: last sequence < 0(-1)

View:

com.couchbase.lite.View viewItemsByDate = database.getView(String.format("%s/%s", designDocName, byDateViewName));
        viewItemsByDate.setMap(new Mapper() {
            @Override
            public void map(Map<String, Object> document, Emitter emitter) {
                Object createdAt = document.get("text");
                if (createdAt != null) {
                    emitter.emit(createdAt.toString(), null);
                }
            }
        }, "1.0");

and My query to this view is:

com.couchbase.lite.View view = database.getView(byDateViewName);
        Query query = view.createQuery();//database.createAllDocumentsQuery();

        List<Object> keyArray = new ArrayList<Object>();
        keyArray.add("A");
        keyArray.add("B");
        query.setKeys(keyArray);

        QueryEnumerator rowEnum = query.run();
        for (Iterator<QueryRow> it = rowEnum; it.hasNext();) {
            QueryRow row = it.next();
            Log.d("Document ID:", row.getDocumentId());

        }

And I have documents in the database with key "text": "A" and "text": "B" but still it is showing me exception. last sequence < 0(-1)

Why it could not find the rows that I queried for?

Was it helpful?

Solution

The problem is that you are querying a different view name than the view name you defined.

Change

database.getView(String.format("%s/%s", designDocName, byDateViewName));

to

database.getView(byDateViewName);

and it fixes the problem.

See Couchbase Lite Android issue #66

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top