I have a Azure Cosmos DB Container 'RouteZipcodes' container. It will have json documents with each route and zipcodes that each route is serving. Below is the sample data stored in cosmos DB
{
"id": "2347z3e8-850d-364a-92d2-4fcae2fa5642",
"routeName": "THORN1",
"zips": [
{ "zipCode": "80373" },
{ "zipCode": "80371" },
{ "zipCode": "80020" },
{ "zipCode": "80370" },
{ "zipCode": "80021" },
{ "zipCode": "80040" },
{ "zipCode": "80602" },
{ "zipCode": "80372" }
],
"status": "A"
}
When I execute below query from portal:
SELECT r.routeName as routeName
FROM routeZipcodes r
JOIN rz in r.zips
where rz.zipCode = "80602"
Below is result:
[ { "routeName": "THORN1" } ]
When I am trying to run same query from Spring boot app, and am not getting any result. Below is my respository
@Repository
public interface RouteZipcodesRepository extends CosmosRepository<RouteZipcodes, String> {
Optional<RouteZipcodes> findById(String id);
Optional<List<RouteZipcodes>> findByHubName(String hubName);
Optional<RouteZipcodes> findByRouteName(String routeName);
// @Query("SELECT r.routeName FROM routeZipcodes r JOIN rz in r.zips where rz.zipCode = \"@zipcode\"")
// String findByZipCode (@Param("zipcode") String zipcode);
@Query("SELECT r.routeName as routeName FROM routeZipcodes r JOIN rz in r.zips where rz.zipCode = \"@zipcode\"")
List<IRouteNameByZipcode> findByZipCode (@Param("zipcode") String zipcode);
}
other methods are working as expected. Only query written with @query is not giving results when the same was working in portal.
SELECT r.routeName as routeName FROM routeZipcodes r WHERE r. zips[0]. zipCode IN ("80373")