Pra*_*eep 6 c# azure azure-cosmosdb
我开发了简单的 Web 应用程序,因为我使用 cosmos 数据库将一些数据保存到其中。到目前为止一切正常。但是每当我尝试从 cosmos 数据库中按时间获取最新值时,\xe2\x80\x99s 需要一分钟多才能给出最新记录。
\n\n这是我为从 cosmos 数据库获取最新记录而编写的代码。
\n\n public static async Task<IEnumerable<IoTHubDataPoint>> GetItemsAsync()\n {\n IDocumentQuery<IoTHubDataPoint> query = client.CreateDocumentQuery<IoTHubDataPoint>(\n UriFactory.CreateDocumentCollectionUri(DatabaseId, CollectionId), \n new FeedOptions { MaxItemCount = 1, EnableCrossPartitionQuery = true}).OrderByDescending(x=>x.Time).Take(1)\n .AsDocumentQuery();\n\n List<IoTHubDataPoint> results = new List<ServiceMaxIoTHubDataPoint>();\n while (query.HasMoreResults)\n {\n results.AddRange(await Task.Run(async () => await query.ExecuteNextAsync<IoTHubDataPoint>()) );\n }\n //return results.OrderByDescending(x => x.Time).Take(1).ToArray();\n return results;\n\n }\nRun Code Online (Sandbox Code Playgroud)\n\n这是 azure cosmos 数据库中可用的示例数据。
\n\n{\n"DeviceID": "IoT-1",\n"Time": "2017-11-02T14:46:06.7846161",\n"Temperature": 28.63403,\n"Pressure": "95089.47",\n"Altitude": "532.5873",\n"LightStatus": "Too Bright",\n"LightCDSValue": "193",\n"LightCDSVoltageValue": "0.943304",\n"EventProcessedUtcTime": "2017-11-02T14:46:40.3930989Z",\n"PartitionId": 0,\n"EventEnqueuedUtcTime": "2017-11-02T14:46:07.6Z",\n"IoTHub": {\n "MessageId": null,\n "CorrelationId": null,\n "ConnectionDeviceId": "IoT-1",\n "ConnectionDeviceGenerationId": "636449561753440920",\n "EnqueuedTime": "2017-11-02T14:46:07.826Z",\n "StreamId": null\n},\n"id": "XXXXXXXXXXXXXX",\n"_rid": "XXXXXXXXXXXXXx",\n"_self": "dbs/4RM3AA==/colls/4RM3AOJ1XQA=/docs/XXXXXXXXXXXx==/",\n"_etag": "\\"XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXx\\"",\n"_attachments": "attachments/",\n"_ts": XXXXXX\n}\nRun Code Online (Sandbox Code Playgroud)\n\n谁能告诉我如何解决上述问题?
\n| 归档时间: |
|
| 查看次数: |
7810 次 |
| 最近记录: |