如何在带有多个WHERE和OR子句的CouchDB中创建视图 [英] How to create a view in CouchDB with multiple WHERE and OR clauses

查看:88
本文介绍了如何在带有多个WHERE和OR子句的CouchDB中创建视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将如何创建与这样的SQL查询等效的视图?

How would I creat a view equivalent to a SQL query like this?

SELECT * FROM bucket WHERE(uid ='$ uid'AND acceptd = 'Y')OR(uid ='$ uid'AND authorid ='$ logginid')

我的数据以这种方式存储:

My data is stored this way:

{
"id": 9476183,
"authorid": 85490,
"content": "some text here",
"uid": 41,
"accepted": "Y",
"time": "2014-12-09 10:44:01",
"type": "testimonial"
}


推荐答案

function(doc) {
    if (doc.accepted == 'Y') {
        emit(doc.uid, null);
    }
    emit([doc.uid, doc.authorid], null);
}

一个请求就足够了。您可以使用带有参数 keys的POST来点击@Simon(复制于上)的视图:[[uid,authorid],uid]

One request is enough. You can tap view written by @Simon (reproduced above) using POST with param keys:[[uid, authorid], uid].

请参见 http://docs.couchdb.org/en/latest/api/ddoc/views.html#post--db-_design-ddoc-_view-view 了解模式详细信息。

See http://docs.couchdb.org/en/latest/api/ddoc/views.html#post--db-_design-ddoc-_view-view for mode details.

这篇关于如何在带有多个WHERE和OR子句的CouchDB中创建视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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