1

We have a requirement to filter the objects of Azure Cosmos DB using datetime field. The structure of the object is as follows.

{
    "nodeId": 3,
    "nodeName": "HAVC",
    "assetId": 2,
    "assetName": "Chiller_02",
    "assetMeasurementId": 22,
    "assetMeasurementName": "CHL01_WATER_ENTER_TEMP",
    "streamId": 0,
    "streamName": null,
    "deviceId": 4,
    "deviceTagId": 48,
    "rawTelemetryData": 49,
    "observationPropertyId": 1,
    "isActive": false,
    "enqueueDatetime": "2019-05-31T07:17:45",
    "receivedDatetime": "2019-06-03T18:51:16.6684284",
    "id": "1e9fe261-5e73-4a64-8921-817a6c601ea0",
    "_rid": "PfsxALhViWYWAAAAAAAAAA==",
    "_self": "dbs/PfsxAA==/colls/PfsxALhViWY=/docs/PfsxALhViWYWAAAAAAAAAA==/",
    "_etag": "\"0000f80f-0000-1800-0000-5cf51e930000\"",
    "_attachments": "attachments/",
    "_ts": 1559568019
}

In this, we need to query the data using 'receivedDatetime' field and we need data between '18:51' to '18:57'

In C#, we use a syntax similar to LINQ

var queryable = client.CreateDocumentQuery<TestDto>(
        UriFactory.CreateDocumentCollectionUri(DatabaseId, CollectionId),
        new { EnableCrossPartitionQuery = true })
    .Where(x => x.receivedDatetime >= DateTime.Parse(startDate))
    .Where(x => x.receivedDatetime <= DateTime.Parse(endDate))
    .OrderBy(x => x.receivedDatetime)
    .AsDocumentQuery();

But we were unable to receive the data as expected. Appreciate if you can kindly provide some support

0

2 Answers 2

1

You can check this -DateTime, the Epoch and DocumentDb You have to store receivedDatetime in ISO-8601 date/time format

Sign up to request clarification or add additional context in comments.

Comments

0

To do efficient range queries on a numeric field in Cosmosdb you have to define a Range Index on the path containing your numeric field when you create the Container.

CosmosDB does not support querying DateTime. You can have a look on the blog here to understand more

1 Comment

Looks like that has been fixed according to this page learn.microsoft.com/da-dk/azure/cosmos-db/sql/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.