我正在尝试为反应式存储库 spring data cosmo DB 创建(使用 spring 本机查询)findAllId。 由于 ReactiveCosmosRepository 尚未实现。
@Query(value = " SELECT *\n" +
" FROM container_name km\n" +
" WHERE km.id IN (@ids) \n" +
" ORDER BY km.createdDate DESC ")
Flux<ContainerData> findAllById(@Param("ids") String[] ids);
甚至
@Query(value = " SELECT *\n" +
" FROM container_name km\n" +
" WHERE km.id IN (@ids) \n" +
" ORDER BY km.createdDate DESC ")
Flux<ContainerData> findAllById(@Param("ids") Iterable<String> ids);
但它没有检索任何结果,也没有抛出任何异常。
所以问题是,如何在 cosmos db 和集合或数组中将 IN 运算符与 spring data 本机查询一起使用,而无需采取解决方法。
你应该使用array_contains
@Query(value = " SELECT *\n" +
" FROM container_name km\n" +
" WHERE array_contains(@ids, km.id, true) \n" +
" ORDER BY km.createdDate DESC ")
Flux<ContainerData> findAllById(@Param("ids") Iterable<String> ids);
@Vova Array_contains 不适合我。我正在尝试传递查询广告:
List<String> list = new ArrayList<>();
list.add("16e41cbf-c2cd-41f1-923f-b2fb313c13fc");
Iterable<String> ids = list;
Flux<MasterData> flux1 = masterDataRepository.findAllById(list);
Mono<List<MasterData>> mono1 = flux1.collectList();
List<MasterData> productsDetail1 = mono1.block();
查询: @Query(value = " SELECT * FROM c WHERE Array_Contains(@ids, c.id)") Flux findAllById(@Param("ids") 列表 ids);