CouchDB返回“错误"消息. total_rows [英] CouchDB returns "wrong" total_rows

查看:64
本文介绍了CouchDB返回“错误"消息. total_rows的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的CouchDB中有5680个文档.

I have 5680 documents in my CouchDB.

我用类似的东西来减少它

I reduced it with something like:

function(doc) {
  if (doc.address.country && doc.cats) {
     for (i = 0; i < doc.cats.length; i++) { 
       emit([doc.address.country, doc.cats[i].id], doc);
     }    
  }
}

通过以下方式运行我的视图: myview?key = ["CC",类别"]

Running my view with: myview?key=["CC","category"]

返回预期结果(25个项目).

Returns the expected result (25 items).

但是响应中有一个字段:

However there is a field in the response:

{"total_rows":5680,"offset":5655, ...

total_rows计数是我的完整数据集,而不仅仅是与我的查询匹配的数据集.有没有办法查看结果中匹配的行?

The total_rows count is my full data set, not only the ones which matched my query. Is there a way to see the matching rows in the result?

我想防止重复添加仅减少功能的地图代码.另外,我想防止两个http请求仅针对该信息.

I would like to prevent duplicating the map code to just add a reduce function. In addition I would like to prevent two http requests just for that information.

对于我来说,这些信息对于实现分页等功能非常有用.

For me this information would be useful to implement something like pagination.

我已阅读以下内容: http://docs.couchdb.org/en/1.6.1 /couchapp/views/pagination.html

I have read this: http://docs.couchdb.org/en/1.6.1/couchapp/views/pagination.html

但是他们没有对我的数据行的有限子集进行分页.

But they are not paginating over a limited subset of my data rows.

我发现,仅从总行中减去偏移量是行不通的(当然).

As I found out, simply substracting offset from the total rows will not work (of course).

如何在响应中获得正确的total_rows数,或者用例中的最佳实践是什么?

How can I have a correct number of total_rows in my response, or what are the best practices in my use case?

谢谢!

推荐答案

total_rows值是视图中的总行数.如果该视图显示数据库中的所有行,则它将是相同的值.您是正确的,它不是该查询中返回的行数.在查询中返回的行数未作为单独的值显示,但是通过获取返回的行数组的长度即可轻松找到.

The total_rows value is the total number of rows in the view. If the view shows all the rows in the database, then that will be the same value. You are correct that it is not the number of rows returned in that query. The number of rows returned in the query is not presented as a separate value, however is is trivially found by getting the length of the returned rows array.

这篇关于CouchDB返回“错误"消息. total_rows的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆