0

I wish to create azure cosmos databases from Java code using the com.microsoft.azure:azure-documentdb:2.4.1. I can only find the option to set offerThroughput which is for collections created in the database.

Does anyone know how to do this?

Jay Gong
  • 23,163
  • 2
  • 27
  • 32
stephen newman
  • 533
  • 4
  • 17

1 Answers1

0

Please use below code:

public static void main(String[] args) throws DocumentClientException {

        DocumentClient client = new DocumentClient(
                YOUR_COSMOS_DB_ENDPOINT,
                YOUR_COSMOS_DB_MASTER_KEY,
                new ConnectionPolicy(),
                ConsistencyLevel.Session);

        RequestOptions requestOptions = new RequestOptions();
        requestOptions.setOfferThroughput(500);

        Database database = new Database();
        database.setId("testdb");
        client.createDatabase(database,requestOptions);
}

If you want to update RU settings, you could refer to my previous case:

1.Reducing Provisioned Throughput for CosmosDB

2.Cosmos Db Throughput

Jay Gong
  • 23,163
  • 2
  • 27
  • 32
  • Thanks Jay, that does create a database with shared throughput . I did see the offer methods on DocumentClient but I didn't find anything that worked. – stephen newman Aug 06 '19 at 23:36
  • My code now fails creating a collection as it must have a partition key when throughput is shared: I have added one programmatically but it fails. I can create a Container using the azure portal with the same partition key and my code can create documents in that Container.... – stephen newman Aug 06 '19 at 23:46
  • but queries fail with this error: com.microsoft.azure.documentdb.DocumentClientException: Cross partition query is required but disabled. Please set x-ms-documentdb-query-enablecrosspartition to true, specify x-ms-documentdb-partitionkey, or revise your query to avoid this exception – stephen newman Aug 06 '19 at 23:46
  • I have concluded not to use shared throughput 1) for integration tests I will tear everything down immediately 2) move low volume tables out of cosmos ( I am in the process of moving a HBase database into cosmos) – stephen newman Aug 06 '19 at 23:52
  • @stephennewman Would you please jump into this room:https://chat.stackoverflow.com/rooms/197589/how-to-provision-throughput-at-the-database-level-in-java-code-using-azure-docume? – Jay Gong Aug 07 '19 at 01:52