连接到azure-cosmosdb,并能够启动默认查询,如findAll()和findById(String Id)。但是我不能使用@Query注释编写原生查询,因为代码没有考虑它。总是在respository类/接口中考虑函数的名称。我需要一种方法来激发一个自定义或原生查询到azure-cosmos db。?!
尝试使用@Query注释。但不起作用。
findBySessionID()正在按预期工作。findSessions()不起作用。在运行代码时出现了根错误。
由:org.springframework.data.mapping.PropertyReferenceException: No property findSessions found for type MonitoringSessions引起
发布于 2019-09-24 09:04:03
谢谢你的回应。我从下面的链接中得到了我想要的东西。信用归于链接页面的作者。
公共班级计划{
private final ExecutorService executorService;
private final Scheduler scheduler;
private AsyncDocumentClient client;
private final String databaseName = "UniversityDatabase";
private final String collectionId = "StudentCollection";
private int numberOfDocuments;
public Program() {
// public constructor
executorService = Executors.newFixedThreadPool(100);
scheduler = Schedulers.from(executorService);
client = new AsyncDocumentClient.Builder().withServiceEndpoint("uri")
.withMasterKeyOrResourceToken("key")
.withConnectionPolicy(ConnectionPolicy.GetDefault()).withConsistencyLevel(ConsistencyLevel.Eventual)
.build();
}
public static void main(String[] args) throws InterruptedException, JSONException {
FeedOptions options = new FeedOptions();
// as this is a multi collection enable cross partition query
options.setEnableCrossPartitionQuery(true);
// note that setMaxItemCount sets the number of items to return in a single page
// result
options.setMaxItemCount(5);
String sql = "SELECT TOP 5 s.studentAlias FROM coll s WHERE s.enrollmentYear = 2018 ORDER BY s.studentAlias";
Program p = new Program();
Observable<FeedResponse<Document>> documentQueryObservable = p.client
.queryDocuments("dbs/" + p.databaseName + "/colls/" + p.collectionId, sql, options);
// observable to an iterator
Iterator<FeedResponse<Document>> it = documentQueryObservable.toBlocking().getIterator();
while (it.hasNext()) {
FeedResponse<Document> page = it.next();
List<Document> results = page.getResults();
// here we iterate over all the items in the page result
for (Object doc : results) {
System.out.println(doc);
}
}
}}
https://stackoverflow.com/questions/57907452
复制相似问题