Azure文档DB orderby timestamp字段

Dus*_*gal 5 azure azure-cosmosdb

timestamp我的每个文件中都有一个字段.时间戳采用ISODate格式.有没有办法在Document Explorer或Query Explorer中使用它对数据进行排序?

que*_*ent 7

每个文档都有一个名为"_ts"的默认时间戳字段.例如,您可以使用以下查询获取最后一个文档:

SELECT * FROM c ORDER BY c._ts DESC


hsu*_*sen 0

将日期存储为纪元,而不是 ISO 日期。如果您需要在文档中提供人类可读的日期,则可以存储两者。

请参阅此https://azure.microsoft.com/en-us/blog/working-with-dates-in-azure-documentdb-4/

- 根据评论和 Larry 的回答,您可以使用精度为 -1 的范围索引(范围索引的要求)。您可以从门户将索引要求设置为 json 或通过代码。

new IncludedPath { 
    Path = "/your_iso_property_path" ,
    Indexes = new Collection<Index> {
        new RangeIndex(DataType.String) { Precision = -1 } 
    }
});
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,请参阅https://azure.microsoft.com/nb-no/documentation/articles/documentdb-indexing-policies/

如果您使用 API 创建集合或不久前使用门户创建集合,则字符串的默认索引将是哈希索引。