在 documentdb 中存储日期时间值的最佳方法是什么? [英] What is the best way to store datetime value in documentdb?

查看:34
本文介绍了在 documentdb 中存储日期时间值的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 是否有在 documentdb 中存储日期时间值的最佳方法?
  2. 显然,我将以 UTC 和 ISO 8601 格式存储这些信息.这有什么问题吗?
  3. 我应该能够基于此日期时间值进行查询,例如 startDateTime <;currentValue 和 currentValue <= endDateTime 等.我应该怎么做才能在这些类型的查询等上获得最大性能.

推荐答案

在你的情况下,你没有提到的唯一真正的关键是你在 ISO-8601 上有一个全精度 (-1) 的范围索引字符串.

In your case, the only real key that you didn't mention is that you have a range index with full precision (-1) on the ISO-8601 strings.

其他一些一般准则:

  • 以规范形式存储所有事件:2016-07-18T01:23:45.678Z

以祖鲁/格林威治标准时间存储所有内容.以 Z 结束每个字符串.永远不要用 +03:00 存储它.在使用该输入运行查询之前,请确保将本地时间从用户输入转换为祖鲁时间.

Store everything in zulu/GMT time. End every string with a Z. Never store it with +03:00. Make sure you shift local time input from the user to zulu time before running queries with that input.

我还建议您根据自己的情况使用最粗的粒度.因此,如果您指的是 2016 年 3 月的整个月份,只需存储 2016-03,而不是 -01T00:00:00.000Z.这主要适用于您在运行查询时使用的文字.假设事件以规范形式存储而不是 2016-07 <2016-07-18T01:23:45.678Z 是真的.此建议主要是为了用户的利益,但不会导致任何性能下降,并且在某些情况下可能会略有改进.

I also recommend that you use the most coarse granularity for your situation. So, if you are referring to the entire month of march, 2016, simply store 2016-03 leaving off the -01T00:00:00.000Z. This mostly applies to the literals you use when running queries. Assuming the events are stored in canonical form than 2016-07 < 2016-07-18T01:23:45.678Z is true. This recommendation is mostly for the benefit of the user, but it won't cause any performance degradation and it's possible that it could be a very slight improvement in some circumstances.

这篇关于在 documentdb 中存储日期时间值的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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