在开始日期和结束日期之间查询 CouchDB 文档 [英] Querying CouchDB documents between a start date and an end date

查看:26
本文介绍了在开始日期和结束日期之间查询 CouchDB 文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图弄清楚如何创建一个 CouchDB 视图,让我可以查询所有开始日期大于 A 且结束日期小于 B 的文档.

I've been trying to figure out how to create a CouchDB view that will let me query all the documents that have a start date greater than A and an end date less than B.

这在 CouchDB 或其他 noSQL 文档存储中是否可行?我应该放弃它并返回 SQL 吗?

Is this possible in CouchDB or another noSQL document store? Should I scrap it and go back to SQL?

我只是尝试执行以下 SQL 等效项:

I'm simply trying to do the SQL equivalent of:

SELECT * WHERE [开始时间戳] >= doc.start AND [结束时间戳] <文档结束;

SELECT * WHERE [start timestamp] >= doc.start AND [end timestamp] < doc.end;

推荐答案

只需像这样创建一个地图:

Just create a map like this:

function (doc) {emit(doc.timestamp, 1)}

然后使用以下命令查询视图:

then query the view with:

?descending=true&limit=10&include_docs=true // Get the latest 10 documents

视图将按从旧到新排序,因此 descending=true 会颠倒该顺序.

The view will be sorted oldest to latest so descending=true reverses that order.

如果你想要一个特定的范围.

If you want a specific range.

?startkey="1970-01-01T00:00:00Z"&endkey="1971-01-01T00:00:00Z"

会在 1970 年为您提供一切.

would get you everything in 1970.

这些应该会有所帮助:

这篇关于在开始日期和结束日期之间查询 CouchDB 文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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