View returns wrong results

Hi,

I am using Version: 4.0.0-4051 Community Edition (build-4051).

I have a view:

function (doc, meta) {
  if (doc.MsgHeaders.JMSTimestamp) {
    	var date = new Date(doc.MsgHeaders.JMSTimestamp);
    	var day = "0" + date.getDate();
        var month = "0"+(date.getMonth()+1);
        var year = date.getFullYear();
    	var formattedTime = year+month.substr(-2)+day.substr(-2);
        if (doc.photoattachment && doc.photoattachment.comment && doc.photoattachment.comment.toLowerCase() == "Batch loading".toLowerCase()) {
                emit("BATCH_"+formattedTime,meta.id);
        }
        else {
                emit(formattedTime,doc);
        }
  } else {
      emit("00000000_"+doc.partnerid,meta.id);
  }
}

The view transforms UNIX timestamp to string representing some date (for example ‘20170101’).
In this view all documents inserted in one day will have the same key.
The problem is sometimes result can vary. For example I want to get all documents for yesterday: in 00:05 I get 4000 documents and one minute after I get 40000.

I tried with Java SDK

ViewResult result = bucket.query(ViewQuery.from("date", "date").development(false).key('20170101')); 

and with Python SDK

Bucket(couch_connection_url, password).query('some_date', 'some_date', query=create_query_for_key('20170101'))

In Couchbase server logs I dont see any errors at this time. Could you please explain why this situation could happend.

Thanks in advance!