Share via

Azure Cosmos DB with Java SDK - SQL query using in filter is not working

Yuvaraj Madheswaran 390 Reputation points
2023-07-06T15:53:25.4966667+00:00

Hi,

I am using Azure SDK with Spring to get the list of data's from cosmos for the given id's .So i composed the query as below,

@Query(value = " SELECT * FROM container_name km WHERE km.id IN (@ids) ")

but it is not retrieving any results, and it is not throwing any exception either.

Azure Cosmos DB
Azure Cosmos DB

An Azure NoSQL database service for app development.

0 comments No comments

Answer accepted by question author

GeethaThatipatri-MSFT 29,597 Reputation points Microsoft Employee Moderator
2023-07-07T02:00:08.3733333+00:00

Hi, @Yuvaraj Madheswaran Welcome to the Microsoft Q&A platform.

Regarding the query you provided, it looks correct, and I don't see any issues with it. However, you can try modifying the query to use a parameterized query instead of string concatenation to pass the ids parameter

@Query(value = "SELECT * FROM container_name km WHERE ARRAY_CONTAINS(@ids, km.id)")
List<MyData> getDataByIds(@Param("ids") List<String> ids);

Regards

Geetha

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Yuvaraj Madheswaran 390 Reputation points
    2023-07-14T16:12:05.6633333+00:00

    Removed the query. Modified the method as below,

    List<MyData> getDataByIdInOrderByIdAsc(List<String> ids);

    This fix the issue.

    Was this answer helpful?


Your answer

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