На основании моего теста все работает нормально.
Вот мой пример:
@RequestMapping({"/","/db"})
@ResponseBody
public String db() {
String result = "";
try {
DocumentClient documentClient = new DocumentClient(
"https://jackdocumentdb.documents.azure.com:443/",
"hcaqayqxz3Jxc*******0v2tkDplDSdax3iW5n64bgfSg==",
ConnectionPolicy.GetDefault(),
ConsistencyLevel.Session);
Database myDatabase = new Database();
myDatabase.setId("database");
try{
documentClient.readDatabase("dbs/database",null);
}catch (Exception e){
logger.info(e.toString());
myDatabase = documentClient.createDatabase(myDatabase, null).getResource();
}
DocumentCollection myCollection = new DocumentCollection();
myCollection.setId("collection");
try{
documentClient.readCollection("dbs/database/colls/collection",null);
}catch (Exception e){
logger.info(e.toString());
RequestOptions requestOptions = new RequestOptions();
requestOptions.setOfferThroughput(400);
myCollection = documentClient.createCollection(
"dbs/database", myCollection, requestOptions)
.getResource();
}
result = myCollection.getSelfLink();
documentClient.close();
} catch (Exception e) {
logger.info(e.toString());
}
return result;
}
Консольные выходы:
2019-10-15 14:11:56.552 INFO 21432 --- [nio-8080-exec-4] c.m.azure.documentdb.DocumentClient : Initializing DocumentClient with serviceEndpoint [https://jackdocumentdb.documents.azure.com:443/], ConnectionPolicy [ConnectionPolicy [requestTimeout=60, directRequestTimeout5, mediaRequestTimeout=300, connectionMode=Gateway, mediaReadMode=Buffered, maxPoolSize=400, idleConnectionTimeout=60, userAgentSuffix=, retryOptions=com.microsoft.azure.documentdb.RetryOptions@1f83947e, enableEndpointDiscovery=true, preferredLocations=null, usingMultipleWriteLocations=false, handleServiceUnavailableFromProxy=false]], ConsistencyLevel [Session]
2019-10-15 14:11:58.548 INFO 21432 --- [nio-8080-exec-4] c.e.viever.controller.MainController : com.microsoft.azure.documentdb.DocumentClientException: Message: {"Errors":["Resource Not Found"]}
ActivityId: eb11a07b-2d34-4676-a930-f9ce48be03bb, Request URI: /apps/4a0a03b0-c5b6-4776-bb7e-7446131c8e1d/services/2704eecf-4c3d-43f8-96ff-9187974116c8/partitions/b3cde68f-b9f0-4ebc-8632-f2c7b75098fe/replicas/132155818573058919s, RequestStats:
RequestStartTime: 2019-10-15T06:11:58.3492376Z, RequestEndTime: 2019-10-15T06:11:58.3492376Z, Number of regions attempted:1
ResponseTime: 2019-10-15T06:11:58.3492376Z, StoreResult: StorePhysicalAddress: rntbd://10.0.0.25:19700/apps/4a0a03b0-c5b6-4776-bb7e-7446131c8e1d/services/2704eecf-4c3d-43f8-96ff-9187974116c8/partitions/b3cde68f-b9f0-4ebc-8632-f2c7b75098fe/replicas/132155818573058919s, LSN: 15, GlobalCommittedLsn: 15, PartitionKeyRangeId: , IsValid: True, StatusCode: 404, SubStatusCode: 0, RequestCharge: 1, ItemLSN: -1, SessionToken: -1#15, UsingLocalLSN: False, TransportException: null, ResourceType: Database, OperationType: Read
ResponseTime: 2019-10-15T06:11:58.3492376Z, StoreResult: StorePhysicalAddress: rntbd://10.0.0.23:19700/apps/4a0a03b0-c5b6-4776-bb7e-7446131c8e1d/services/2704eecf-4c3d-43f8-96ff-9187974116c8/partitions/b3cde68f-b9f0-4ebc-8632-f2c7b75098fe/replicas/132155923342596657s, LSN: -1, GlobalCommittedLsn: -1, PartitionKeyRangeId: , IsValid: False, StatusCode: 410, SubStatusCode: 0, RequestCharge: 0, ItemLSN: -1, SessionToken: , UsingLocalLSN: False, TransportException: null, ResourceType: Database, OperationType: Read
ResponseTime: 2019-10-15T06:11:58.3492376Z, StoreResult: StorePhysicalAddress: rntbd://10.0.0.19:17000/apps/4a0a03b0-c5b6-4776-bb7e-7446131c8e1d/services/2704eecf-4c3d-43f8-96ff-9187974116c8/partitions/b3cde68f-b9f0-4ebc-8632-f2c7b75098fe/replicas/132155818573058918s, LSN: 15, GlobalCommittedLsn: 15, PartitionKeyRangeId: , IsValid: True, StatusCode: 404, SubStatusCode: 0, RequestCharge: 1, ItemLSN: -1, SessionToken: -1#15, UsingLocalLSN: False, TransportException: null, ResourceType: Database, OperationType: Read
, SDK: Microsoft.Azure.Documents.Common/2.7.0, StatusCode: NotFound
2019-10-15 14:11:59.364 INFO 21432 --- [nio-8080-exec-4] c.e.viever.controller.MainController : com.microsoft.azure.documentdb.DocumentClientException: Message: {"Errors":["Resource Not Found"]}
ActivityId: a87315f9-b2de-4c88-b11e-d02f73434bd3, Request URI: /apps/4a0a03b0-c5b6-4776-bb7e-7446131c8e1d/services/2704eecf-4c3d-43f8-96ff-9187974116c8/partitions/b3cde68f-b9f0-4ebc-8632-f2c7b75098fe/replicas/132155933903772782s, RequestStats:
RequestStartTime: 2019-10-15T06:11:58.7092159Z, RequestEndTime: 2019-10-15T06:11:58.7092159Z, Number of regions attempted:1
ResponseTime: 2019-10-15T06:11:58.7092159Z, StoreResult: StorePhysicalAddress: rntbd://10.0.0.28:19700/apps/4a0a03b0-c5b6-4776-bb7e-7446131c8e1d/services/2704eecf-4c3d-43f8-96ff-9187974116c8/partitions/b3cde68f-b9f0-4ebc-8632-f2c7b75098fe/replicas/132155933903772782s, LSN: 16, GlobalCommittedLsn: 16, PartitionKeyRangeId: , IsValid: True, StatusCode: 404, SubStatusCode: 0, RequestCharge: 1, ItemLSN: -1, SessionToken: -1#16, UsingLocalLSN: False, TransportException: null, ResourceType: Collection, OperationType: Read
ResponseTime: 2019-10-15T06:11:58.7092159Z, StoreResult: StorePhysicalAddress: rntbd://10.0.0.19:17000/apps/4a0a03b0-c5b6-4776-bb7e-7446131c8e1d/services/2704eecf-4c3d-43f8-96ff-9187974116c8/partitions/b3cde68f-b9f0-4ebc-8632-f2c7b75098fe/replicas/132155818573058918s, LSN: 16, GlobalCommittedLsn: 16, PartitionKeyRangeId: , IsValid: True, StatusCode: 404, SubStatusCode: 0, RequestCharge: 1, ItemLSN: -1, SessionToken: -1#16, UsingLocalLSN: False, TransportException: null, ResourceType: Collection, OperationType: Read
, SDK: Microsoft.Azure.Documents.Common/2.7.0, StatusCode: NotFound
2019-10-15 14:12:00.042 INFO 21432 --- [nio-8080-exec-4] c.m.azure.documentdb.DocumentClient : Closing DocumentClient
В выходных данных я получаю два исключения, оба из которых не найдены, исключение. Это правильно, потому что это новый документ БД, и ничего не было создано.
И, наконец, я вижу, что целевая база данных и целевая коллекция создаются из портала:
Предложения:
Вы можете проверить подробное исключение, чтобы увидеть, что именно является причиной вашей проблемы. Может быть, это просто проблема с подключением.