必须为此操作提供 PartitionKey 值
PartitionKey value must be supplied for this operation
我正在尝试从 Azure Cosmos Db 集合中检索文档。我 运行 出错了
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.UnsupportedOperationException: PartitionKey value must be supplied for this operation.] with root cause
java.lang.UnsupportedOperationException: PartitionKey value must be supplied for this operation.
我试图在线查找如何为函数 findById() 提供分区键值,但似乎 "Azure Spring data cosmosdb" 没有提供分区键的选项java 实现的函数
orderTransactionRepository.findById("id").get
搜索了 test code of findById method for partitioned collection which is mentioned in the home page of spring-data-cosmos。
@Test
public void testFindByIdForPartitionedCollection() {
final List<Address> addresses = repository.findByPostalCode(TestConstants.POSTAL_CODE);
assertThat(addresses.size()).isEqualTo(2);
assertThat(addresses.get(0).getPostalCode().equals(TestConstants.POSTAL_CODE));
assertThat(addresses.get(1).getPostalCode().equals(TestConstants.POSTAL_CODE));
}
您可以找到语句 here:
对于Partitioned collection,如果要通过findById(id)查询记录,会抛出异常。
// Incorrect for partitioned collection, exception will be thrown
Address result = repository.findById(id); // Caution: Works for non-partitioned collection
相反,您可以使用自定义查询按 ID 字段名称查询记录。
// Correct, postalCode is the ID field in Address domain
@Repository
public interface AddressRepository extends DocumentDbRepository<Address, String> {
List<Address> findByPostalCode(String postalCode);
}
// Query
List<Address> result = repository.findByPostalCode(postalCode);
另一种方式我发现你仍然可以使用spring-data-cosmos包中的Document DB normal sdk,你只需要简单地封装该方法即可。请参考这个sample code.
只是为了总结,这基本上是由于 Spring 数据共享更改了 querylookupstrategy 正在实施的接口名称。你需要回到之前的版本cosmos-db i.e. 2.0.5
!这是 link 说明问题 github.com/Microsoft/spring-data-cosmosdb/issues/304
我正在尝试从 Azure Cosmos Db 集合中检索文档。我 运行 出错了
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.UnsupportedOperationException: PartitionKey value must be supplied for this operation.] with root cause
java.lang.UnsupportedOperationException: PartitionKey value must be supplied for this operation.
我试图在线查找如何为函数 findById() 提供分区键值,但似乎 "Azure Spring data cosmosdb" 没有提供分区键的选项java 实现的函数
orderTransactionRepository.findById("id").get
搜索了 test code of findById method for partitioned collection which is mentioned in the home page of spring-data-cosmos。
@Test
public void testFindByIdForPartitionedCollection() {
final List<Address> addresses = repository.findByPostalCode(TestConstants.POSTAL_CODE);
assertThat(addresses.size()).isEqualTo(2);
assertThat(addresses.get(0).getPostalCode().equals(TestConstants.POSTAL_CODE));
assertThat(addresses.get(1).getPostalCode().equals(TestConstants.POSTAL_CODE));
}
您可以找到语句 here:
对于Partitioned collection,如果要通过findById(id)查询记录,会抛出异常。
// Incorrect for partitioned collection, exception will be thrown
Address result = repository.findById(id); // Caution: Works for non-partitioned collection
相反,您可以使用自定义查询按 ID 字段名称查询记录。
// Correct, postalCode is the ID field in Address domain
@Repository
public interface AddressRepository extends DocumentDbRepository<Address, String> {
List<Address> findByPostalCode(String postalCode);
}
// Query
List<Address> result = repository.findByPostalCode(postalCode);
另一种方式我发现你仍然可以使用spring-data-cosmos包中的Document DB normal sdk,你只需要简单地封装该方法即可。请参考这个sample code.
只是为了总结,这基本上是由于 Spring 数据共享更改了 querylookupstrategy 正在实施的接口名称。你需要回到之前的版本cosmos-db i.e. 2.0.5
!这是 link 说明问题 github.com/Microsoft/spring-data-cosmosdb/issues/304