Couchbase文档日期搜索-DateTime.Now() [英] Couchbase document dates search - DateTime.Now()

查看:43
本文介绍了Couchbase文档日期搜索-DateTime.Now()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在CB中有一个文档,其中有两个日期,开始日期和结束日期.比方说,产品的价格折扣.从今天开始至下周五结束有10%的折扣.我怎样才能从CB获得今天有有效折扣的所有文件?

I have a document in CB which has two dates, a start date and an end date. Let's say, a product's price discount. 10% off starting from today and ends next Friday. How can I get all the documents from CB which have a valid discount today?

我进行了查看,并包含以下内容:

I made a view and have the following in it:

var dt = new Date();

获得今天的日期.然后我可以做一个简单的

Which gets today's date. Then I can do a simple

if(doc.FromDate < dt && doc.ToDate > dt){ emit([ ..... ]);

这将根据需要过滤文档.但是...

This filters the documents how I want. But...

问题

这是重新查看和更新​​索引的好方法吗?索引会因为日期更改而每天更新吗?只是试图了解CB在这方面的工作

Is this a good approach re view and index updating? Will the index update every day because the date changed? Just trying to understand the working of CB in this respect

这种搜索的最佳方法是什么?如果不可能的话,请告诉我!

What is the best approach for this type of searching? If not possible please tell me!

欢呼

罗宾

注意:请注意,问题不是这样的此处或此此处

Note: Please note, the question is NOT like this here or this here

推荐答案

仅由于系统日期已更改,索引将不会更新,您必须更新文档.另外,视图索引器不允许您传递用户定义的任何参数.在这种情况下,您应该发出数据并将日期用作过滤视图查询的关键字的一部分.我猜SQL索引也有相同的行为.您无法预测该文档将在何时准确建立索引,在您的示例中,您在文档被建立索引时冻结了时间戳,甚至没有时间更改文档

the index won't be updated just because system date changed, you have to update the document. also view indexer doesn't allow you to pass any arguments defined by user. in this case you should emit the data and use date as a part of the key to filter on view query. I guess the same behaviour for SQL indexes too. you cannot predict when exactly this document will indexed, in your example you are freezing timestamp when the doc has been indexed, it isn't even the time when it was changed

这篇关于Couchbase文档日期搜索-DateTime.Now()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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