azure-cosmosdb - 在 WHERE 条件下使用日期时间过滤器进行 Cosmos db sql api 查询
问题描述
试图获取修改日期(日期时间)等于(当前日期 -7)但不工作的那些文档,伪代码如下
"SELECT * FROM c where c.LastModifiedDate = (GetCurrentDate-7)"
如何使用 cosmosdb sql api 做到这一点?没有 udf,因为我们有基于计时器触发器的 Azure 函数,该函数在每次触发时直接使用上述SQL 查询查询 Cosmos DB,并将结果绑定到函数的参数。
[FunctionName("TimerCosmosDbWriteExample")]
public static async Task Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer,
TraceWriter log,
[CosmosDB(
databaseName: "Database",
collectionName: "Collection",
ConnectionStringSetting = "MyConnectionString",
SqlQuery = "SELECT * FROM c where c.LastModifiedDate = GetCurrentDate-7")] IEnumerable<Entity> documents)
{
//function body -- loop through retrieved documents & process it
}
解决方案
我有2个观点供你参考:
1.由于在azure函数中调用sql查询,所以可以currentDate-7
用代码计算,然后将其作为参数传递给查询sql。这是一种常见的用法,只需匹配LastModifiedDate
列的格式。
2.我不知道你为什么说你不能在azure函数中使用udf和sql查询,这没有意义。据我所知,UDF是SQL的一部分。请参考我之前的案例:Query a specific time range data from cosmos db and store it in sql database via azure data factory
推荐阅读
- javascript - 如何使用 redux-saga 发出异步请求
- .net - 如何在 IIS 上托管的 wcf 服务中使用 http 请求访问任何方法?
- java - 为什么我在创建 SprintBoot 项目时只能选择 java 8 或 11
- javascript - 如何在Javascript中找到两个UTC时间之间的差异?
- php - 顶部显示很多 php 进程正在休眠
- java - DateTimeFormatter 为边缘情况提供错误的格式
- android - 如何在另一个 ViewModel 中使用来自一个 ViewModel 的数据
- applescript - 不同系统版本Applescript功能差异
- python - Pygame如何通过一系列函数在屏幕上显示单词
- apache-spark - 如何使用结构化流检查点管理 HDFS 内存