Azure / azure-cosmosdb-java

Java Async SDK for SQL API of Azure Cosmos DB
MIT License
54 stars 61 forks source link

Create resource if exists #71

Closed timja closed 5 years ago

timja commented 5 years ago

Hi

Is it possible to create a resource only if it doesn't exist? i.e. a database or a collection,

currently it seems a bit clunky

I had a look at what the tests do to get around this, and they do a delete and create which isn't feasible for production usage.

I'm currently checking if they exist and then creating if needed. But the code I have isn't the nicest

as I want to do a:

createIfNotExists(db)
 .flatMap(createIfNotExistsCollection)
 .flatMap(createIfNotExistsAnotherCollection)
simplynaveen20 commented 5 years ago

Hi Tim, Thanks for reaching out , These is a Helper.java in example project of the code doing the same thing which you can refer ,

https://github.com/Azure/azure-cosmosdb-java/blob/master/examples/src/main/java/com/microsoft/azure/cosmosdb/rx/examples/multimaster/Helpers.java createDatabaseIfNotExists createCollectionIfNotExists

timja commented 5 years ago

Thanks looks perfect, any reason its not in the core code? looks useful

simplynaveen20 commented 5 years ago

Hi Tim, Thanks for reaching out , These is a Helper.java in example project of the code doing the same thing which you can refer ,

https://github.com/Azure/azure-cosmosdb-java/blob/master/examples/src/main/java/com/microsoft/azure/cosmosdb/rx/examples/multimaster/Helpers.java createDatabaseIfNotExists createCollectionIfNotExists

Thanks looks perfect, any reason its not in the core code? looks useful

Glad it helped !! Yes we are planning to include within the SDK in future release.