CosmosDbKeyEscape Class

  • java.lang.Object
    • com.microsoft.bot.azure.CosmosDbKeyEscape

public final class CosmosDbKeyEscape

Helper class to escape CosmosDB keys.

Field Summary

Modifier and Type Field and Description
static final java.lang.Integer MAX_KEY_LENGTH

Older libraries had a max key length of 255.

Method Summary

Modifier and Type Method and Description
static java.lang.String escapeKey(String key)

Converts the key into a DocumentID that can be used safely with Cosmos DB.

static java.lang.String escapeKey(String key, String suffix, Boolean compatibilityMode)

Converts the key into a DocumentID that can be used safely with Cosmos DB.

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Field Details

MAX_KEY_LENGTH

public static final Integer MAX_KEY_LENGTH

Older libraries had a max key length of 255. The limit is now 1023. In this library, 255 remains the default for backwards compat. To override this behavior, and use the longer limit set CosmosDbPartitionedStorageOptions.CompatibilityMode to false. https://docs.microsoft.com/en-us/azure/cosmos-db/concepts-limits\#per-item-limits.

Method Details

escapeKey

public static String escapeKey(String key)

Converts the key into a DocumentID that can be used safely with Cosmos DB.

Parameters:

key - The key to escape.

Returns:

An escaped key that can be used safely with CosmosDB.

escapeKey

public static String escapeKey(String key, String suffix, Boolean compatibilityMode)

Converts the key into a DocumentID that can be used safely with Cosmos DB.

Parameters:

key - The key to escape.
suffix - The string to add at the end of all row keys.
compatibilityMode - True if running in compatability mode and keys should be truncated in order to support previous CosmosDb max key length of 255. This behavior can be overridden by setting CosmosDbPartitionedStorage.compatibilityMode to false. *

Returns:

An escaped key that can be used safely with CosmosDB.

Applies to