Skip to content
Advertisement

CosmosDatabase.createContainerIfNotExists() -> “Resource with specified id, name, or unique index already exists.”

If I call the the method: CosmosDatabase.createContainerIfNotExists(x) I receive the error message: Resource with specified id, name, or unique index already exists.

How I have to interpret this error?

The full exception stacktrace:

JavaScript

Advertisement

Answer

I work around the problem with a try catch block and repeat the operation if this error occur. Debug code show that the container exists after the exception occur.

Our application is multi threading with lazy initialization. Can be that 2 threads try to create the needed container at the same time. The error is difficult to reproduce.

Its sounds this method is not atomic on the database like the method name suggested and also does not handle it in the driver. The very bad API documentation does not says any over thread behavior. With such API documentation it is not possible to write stable software. It required a try and error.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement