简体   繁体   English

Azure Cosmos DB 日期查询作为字符串不起作用

[英]Azure Cosmos DB Date Query as string not working

Basically its just query get operation in azure cosmos db based on machine id and datetime.基本上它只是根据机器 ID 和日期时间在 azure cosmos db 中查询获取操作。 I am really stuck on querying in cosmos based on datetime.The same query I am able to run and get the result on azure portal.But code wise I am not getting the result.我真的坚持基于日期时间在 cosmos 中查询。我能够运行相同的查询并在 azure 门户网站上获得结果。但是代码方面我没有得到结果。

A few more details:更多细节:

SELECT *
FROM c
WHERE c.IoTHub.ConnectionDeviceId IN ('hub20') AND c.MACHINE_ID = 'TAP_20' AND (c.EventEnqueuedUtcTime >= '2021-02-03T10:40:42.5180000Z' AND c.EventEnqueuedUtcTime <= '2021-02-03T10:40:42.5180000Z')
QueryDefinition queryDefinition = new QueryDefinition(sqlQueryText);
FeedIterator<dynamic> queryResultSetIterator = container.GetItemQueryIterator<dynamic>(queryDefinition);
FeedResponse<dynamic> currentResultSet;
while (queryResultSetIterator.HasMoreResults)
{
    currentResultSet = await queryResultSetIterator.ReadNextAsync();
}     

I am able to get all the data till MACHINE_ID but as soon as I apply c.EventEnqueuedUtcTime condition.我能够获取直到 MACHINE_ID 的所有数据,但只要我应用 c.EventEnqueuedUtcTime 条件。 I am not able to get the data.I tried every possible solution.c.EventEnqueuedUtcTime value we are getting as a string and also in database it is saved as string as you can see in the image.我无法获取数据。我尝试了所有可能的解决方案。c.EventEnqueuedUtcTime 值我们作为字符串获取,并且在数据库中它被保存为字符串,如图所示。

{
    "MESSAGE_GROUP_ID": "24c9e3ad-4fd6-4abb-88d8-eafb9060884e",
    "TYPE": "Gauges",
    "MACHINE_ID": "TAP_20",
    "Gauges": {
        "OVERRIDE": 85.8
    },
    "EventProcessedUtcTime": "2021-02-03T10:41:48.0493615Z",
    "PartitionId": 3,
    "EventEnqueuedUtcTime": "2021-02-03T10:40:42.5180000Z",
    "IoTHub": {
        "MessageId": "498b7df3-55e6-4b3f-a18e-698fd991e526",
        "CorrelationId": null,
        "ConnectionDeviceId": "hub20",
        "ConnectionDeviceGenerationId": "637332663098221999",
        "EnqueuedTime": "2021-02-03T10:41:11.2570000Z"
    },
    "id": "498b7df3-55e6-4b3f-a18e-698fd991e526"
}

在此处输入图像描述

Any lead will be appreciated.任何线索将不胜感激。 Thanks谢谢

Thank you user2911592 for sharing the resolution steps.感谢user2911592分享解决步骤。 Posting them as answer to help other community members.将它们作为答案发布以帮助其他社区成员。

Initially the query/code was saved incorrectly using casting.最初使用转换错误地保存了查询/代码。 Fixing the same resolved the issue.修复相同的问题解决了这个问题。

user2911592 : feel free to add furthermore details. user2911592 :随时添加更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM