Limit + Skip bug in views


#1

Hello,

Today I found a weird behaviour using Couchbase Server(4.1.0-5005 Enterprise Edition (build-5005) from docker) and Sync Gateway(1.2 from docker).

I created a view through Couchbase Sync Gateway to filter some data by client phone number to be used in a front-end with pagination. Everything was working fine. If I sent “limit=10&skip=10” it would skip the first 10 rows and show the next rows limiting to 10.

Today I arrived at the office and the pagination was not working.

%  http --session=test http://localhost:8092/default/_design/clients/_view/list_by_client_number\?inclusive_end\=true\&stale\=false\&connection_timeout\=60000\&limit\=10\&skip\=10
HTTP/1.1 200 OK
Cache-Control: must-revalidate
Content-Type: text/plain;charset=utf-8
Date: Mon, 11 Apr 2016 08:35:33 GMT
Server: MochiWeb/1.0 (Any of you quaids got a smint?)
Transfer-Encoding: chunked

{"total_rows":68,"rows":[
]
}

%  http --session=test http://localhost:8092/default/_design/clients/_view/list_by_client_number\?inclusive_end\=true\&stale\=false\&connection_timeout\=60000\&limit\=10          
HTTP/1.1 200 OK
Cache-Control: must-revalidate
Content-Type: text/plain;charset=utf-8
Date: Mon, 11 Apr 2016 08:35:44 GMT
Server: MochiWeb/1.0 (Any of you quaids got a smint?)
Transfer-Encoding: chunked

{"total_rows":68,"rows":[
{...},
{...},
{...},
{...},
{...},
{...},
{...},
{...},
{...},
{...}
]
}

What was happening is that the query was being limited and the using skip. So if want “limit=10&skip=10” it would return 0 rows, but if I ran “limit=20&skip=10”, it would work as “limit=10&skip=10”.

I restarted the Couchbase Server and Couchbase Sync Gateway but still having the same issue. After we recreated the view, everything was working again as expected.

Anyone else experienced something similar?


#2

This is how we created the view:

desing.json

{
  "views":{
    "list_by_client_number": {
        "map": "function (doc, meta) { if(meta.type == 'json' && doc.client && doc.client.client_number) { var attachments = []; if (doc._attachments) { attachments = Object.keys(doc._attachments) }; emit(doc.client.client_number, {'attachments': attachments, 'media': doc.media, 'client': doc.client}); } }"
 
    }
  }
}
http PUT http://localhost:4985/default/_design/clients @design.json

#3

Hi Rafael, Couple of clarification questions -

  • Did you see this behavior only on Docker image? Have you tested this on other machine (Linux, MAC or Windows)?
  • Can you reproduce the issue? if ‘yes’ can you collect logs using cbcollect_info and create a JIRA issue and attach logs

Thanks!

Anil Kumar