简体   繁体   English

将此mysql转换为ouchdb视图?

[英]translate this mysql into a couchdb view?

I'm quite new with couchdb and I want to create a view based on a simple mysql statement. 我对ouchdb很陌生,我想基于一个简单的mysql语句创建一个视图。 I found this documentation: http://guide.couchdb.org/draft/cookbook.html but there are sadly not all use cases included. 我找到了以下文档: http : //guide.couchdb.org/draft/cookbook.html,但可悲的是,并未包括所有用例。

My MySQL-Statement: 我的MySQL声明:

SELECT `title`, `id`, `author`, `date`, `text` FROM `news` WHERE `date`<=NOW() AND `author`='22' ORDER BY `date` DESC LIMIT 20,10;

Thank you very much! 非常感谢你!

You need to write a view with the following map function. 您需要使用以下地图功能编写视图。

function(doc) {
    emit([doc.author, doc.date], {
            "title": doc.title, 
            "author": doc.author, 
            "date": doc.date, 
            "text": doc.text});
}

Now you can query the view using the following URL: 现在,您可以使用以下URL查询视图:

http://127.0.0.1:5984/dbname/_design/design_doc_name/_view/viewname?startkey=[22, "2010-11-12T10:20:30"]&endkey=[22, {}]&descending=true&skip=20&limit=10

The date in the start key must be the current datetime. 开始键中的日期必须是当前日期时间。 There is no way to emulate NOW() in couchdb. 无法在ouchdb中模拟NOW()

A view in couchdb is just a list of key-value pairs sorted by key and it provides a way to access a range of that list. couchdb中的视图只是按键排序的键值对列表,它提供了一种访问该列表范围的方法。 You need to design your view such that you can get the results that you need using a range query. 您需要设计视图,以便可以使用范围查询获得所需的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM