Azure cosmos Db Criteria query with subdocuments - java spring boot

Sibi Sundarrajan 1 Reputation point
2021-02-03T07:49:15.86+00:00

I'm new to azure cosmos db. i'm trying to read items from container in my spring boot application. i'm using cosmos template with criteria. lets say i have a document like this
{
"stop_id": 70021,
"stop_name": "CALTRAIN - 22ND ST STATION",
"stop_lat": 37.757692,
"stop_lon": -122.392318,
"zone_id": 3329,
"trip": [{
"trip_id": "RTD8997283",
"arrival_time": "05:40:00",
"departure_time": "05:40:00",
"stop_id": 70021,
"stop_sequence": 1
}, {
"trip_id": "RTD8997283",
"arrival_time": "05:52:00",
"departure_time": "05:52:00",
"stop_id": 70021,
"stop_sequence": 2
}]
}

i can add criteria for stop id like this
Criteria.getInstance(CriteriaType.IS_EQUAL, "stop_id", Collections.singletonList("70021"), Part.IgnoreCaseType.ALWAYS);

But if i want to add criteira for trip id, how can i do it?

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,700 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anurag Sharma 17,606 Reputation points
    2021-02-04T06:10:52.467+00:00

    Hi @Sibi Sundarrajan , welcome to Microsoft Q&A forum.

    Can you please try something like below and see if it works:

    Criteria.getInstance(CriteriaType.IS_EQUAL, "trip.trip_id", Collections.singletonList("RTD8997283"), Part.IgnoreCaseType.ALWAYS);  
    

    Please let us know if this does not work and we can look into it further.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.