Sdílet prostřednictvím


CosmosDBOutput Interface

Implements

java.lang.annotation.Annotation

public interface CosmosDBOutput
implements java.lang.annotation.Annotation

Place this on a parameter whose value would be written to CosmosDB. The parameter type should be OutputBinding, where T could be one of:

  • Some native Java types such as String
  • Any POJO type

The following example shows a Java function that adds a document to a database, using data provided in the body of an HTTP Post request.

@FunctionName("addItem")

 public String cosmosDbAddItem(
    @HttpTrigger(name = "request", methods = {HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS)
     final String message,
    @CosmosDBOutput(name = "database", databaseName = "ToDoList", collectionName = "Items", 
    connectionStringSetting = "AzureCosmosDBConnection")
 ) {
     return "{ \"id\": \"" + System.currentTimeMillis() + "\", \"description\": \"" + message + "\" }";
 }

Method Summary

Modifier and Type Method and Description
abstract java.lang.String collectionName()

Defines the collection name of the CosmosDB to which to write.

abstract int collectionThroughput()

If CreateIfNotExists is true, defines the throughput of the created collection.

abstract java.lang.String connectionStringSetting()

Defines the app setting name that contains the CosmosDB connection string.

abstract boolean createIfNotExists()

Defines the ID of the CosmosDB to which to write.

abstract java.lang.String dataType()

Defines how Functions runtime should treat the parameter value.

abstract java.lang.String databaseName()

Defines the database name of the CosmosDB to which to write.

abstract java.lang.String name()

The variable name used in function.json.

abstract java.lang.String partitionKey()

Defines the partition key path for the created collection when createIfNotExists is set to true.

abstract java.lang.String preferredLocations()

Defines preferred locations (regions) for geo-replicated database accounts in the Azure Cosmos DB service.

abstract boolean useMultipleWriteLocations()

Enable to use with Multi Master accounts.

Method Details

collectionName

public abstract String collectionName()

Defines the collection name of the CosmosDB to which to write.

Returns:

The collection name string.

collectionThroughput

public abstract int collectionThroughput()

If CreateIfNotExists is true, defines the throughput of the created collection.

Returns:

Throughput of the created collection.

connectionStringSetting

public abstract String connectionStringSetting()

Defines the app setting name that contains the CosmosDB connection string.

Returns:

The app setting name of the connection string.

createIfNotExists

public abstract boolean createIfNotExists()

Defines the ID of the CosmosDB to which to write.

Returns:

The ID string.

dataType

public abstract String dataType()

Defines how Functions runtime should treat the parameter value. Possible values are:

  • "" or string: treat it as a string whose value is serialized from the parameter
  • binary: treat it as a binary data whose value comes from for example OutputBinding<byte[]>

Returns:

The dataType which will be used by the Functions runtime.

databaseName

public abstract String databaseName()

Defines the database name of the CosmosDB to which to write.

Returns:

The database name string.

name

public abstract String name()

The variable name used in function.json.

Returns:

The variable name used in function.json.

partitionKey

public abstract String partitionKey()

Defines the partition key path for the created collection when createIfNotExists is set to true. May include binding parameters.

Returns:

partitionKey of the created collection.

preferredLocations

public abstract String preferredLocations()

Defines preferred locations (regions) for geo-replicated database accounts in the Azure Cosmos DB service. Values should be comma-separated. example, PreferredLocations = "East US,South Central US,North Europe"

Returns:

PreferredLocations for geo-replicated database accounts

useMultipleWriteLocations

public abstract boolean useMultipleWriteLocations()

Enable to use with Multi Master accounts.

Returns:

whether to Multi Master accounts

Applies to