选择不同的计数 cloudant/couchdb

编程入门 行业动态 更新时间:2024-10-27 13:21:01
本文介绍了选择不同的计数 cloudant/couchdb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用 Cloudant 开始一个项目.这是一个简单的日志记录系统,因此我可以跟踪我的应用程序的使用情况.

I am starting a project using Cloudant. It's a simple system for logging, so I can track the usage of my apps.

我的文档如下所示:

{ app:'应用名称',类型:'页面浏览量 |登录 |等等..',所有者:'email_of_the_user',设备:'iphone |安卓 |等等..', 日期:'yyyy-mm-dd'}

{ app:'name of the app', type:'page view | login | etc..', owner:'email_of_the_user', device: 'iphone | android | etc..', date: 'yyyy-mm-dd' }

我尝试进行一些地图缩减和分面搜索,但到目前为止找不到我想要的结果.

I've tried to do some map reducing and faceted searches, but couldn't find so far the result for what I want.

我想计算按同一所有者、日期 (yyyy-mm-dd) 和应用分组的不同文档的数量.

I want to count the number of distinct documents grouped by same owner, date (yyyy-mm-dd), and app.

[例如,同一个人在同一日期登录应用程序两次或二十次,则仅计为一次.我想统计每天有多少单个用户使用了一个应用程序,无论日志的类型是什么,或者他使用的设备是什么.]

[For example, if a the same guy logs in the app twice or 20 times in the same date, it will be counted only once. I want to count how many single users used an app each day, no matter what's the type of the log, or the device he used.]

如果是 SQL,假设文档的每个键都是一列,我会这样查询:

If it was SQL, assuming that each key of the document is a column, I would query something like this:

SELECT app, date, count(*) FROM LOGS group by date, owner, app

SELECT app, date, count(*) FROM LOGS group by date, owner, app

结果会是这样的:

'App1', '2015-06-01', 200'App1', '2015-06-02', 232'App2', '2015-06-01', 142'App2', '2015-06-02', 120

'App1', '2015-06-01', 200 'App1', '2015-06-02', 232 'App2', '2015-06-01', 142 'App2', '2015-06-02', 120

如何使用 Cloudant/CouchDB 获得相同的结果?

How can I get the same result using Cloudant/CouchDB?

推荐答案

正如 Cesar 所说,您可以使用设计文档来做到这一点.一个具体的例子是创建一个视图,您的地图函数会在您想要分组的地方发出字段,例如:

You can do this using design documents, as Cesar mentioned. A concrete example would be to create a view where your map function emits the field on where you want to group on, such as:

function(doc) { emit(doc.email, 1); }

然后,您选择所需的 reduce 函数(例如 _count).在 Cloudant 仪表板上查看此内容时,请确保选择 Reduce 作为查询选项的一部分.通过 URL 访问视图时,您需要传递适当的参数 (reduce=true&group=true).

Then, you select your desired reduce function (such as _count). When viewing this on Cloudant dashboard, make sure you select Reduce as part of the query options. When accessing the view via URL you need to pass the appropriate parameters (reduce=true&group=true).

此处有关视图的文档非常详尽:docs.cloudant/creating_views.html

The documentation on Views here is pretty thorough: docs.cloudant/creating_views.html

更多推荐

选择不同的计数 cloudant/couchdb

本文发布于:2023-10-30 03:51:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1541672.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:cloudant   couchdb

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!