我反驳了同样的问题,用递归函数
const batchSize = 25;
let batchCount = 0;
let searchResults = [];
// in my case I want to find docs with a certain date, hardcoded here as example
let selectedDate = '2017/10/30';
// the recursive function
let search = function (count, limit){
return db.find({
selector: {
date: selectedDate
},
limit: batchSize,
skip: batchCount*batchSize
}).then(function(batch){
if (batch.docs.length === 0){
// there are no (more) search results, so we can return what we have
return searchResults
} else {
// there may be more search results, so we add this batch to the result and call the function again to ask more. We increase the counter so that the first batch(es) are skipped
for (var i = 0; i < batch.docs.length; i++) {
searchResults.push(batch.docs[i])
}
batchCount ++
return search(batchCount, batchSize)
}
})
}
search(batchCount, batchSize).then(function(result){
// you can handle the searchresults
})
使用CouchDB 2.1解决它,你可以更改默认限制。因此,我认为你不能避免这个限制。无论如何,你应该有一个限制,因为你有更多的结果,处理和发送通过http需要的时间越长。你应该总是设计你的代码来处理请求的分页。 –
@AlexisCôté谢谢亚历克西斯! :)我会采用分页方法,因为它似乎是一个更好的选择,在这一点上唯一的选择。 –
我的不好,分页还没有被支持(看起来它会成为下一个版本的一部分),我想你可以暂时把一个高数字作为极限。 –