@Retention(value=RUNTIME) @Target(value={PARAMETER,METHOD}) public @interface CosmosDBOutput
Place this on a parameter whose value would be written to CosmosDB. The parameter type should be OutputBinding<T>, where T could be one of:
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 + "\" }";
}
| Modifier and Type | Required Element and Description |
|---|---|
String |
collectionName
Defines the collection name of the CosmosDB to which to write.
|
String |
connectionStringSetting
Defines the app setting name that contains the CosmosDB connection string.
|
String |
databaseName
Defines the database name of the CosmosDB to which to write.
|
String |
name
The variable name used in function.json.
|
| Modifier and Type | Optional Element and Description |
|---|---|
int |
collectionThroughput
If CreateIfNotExists is true, defines the throughput of the created collection.
|
boolean |
createIfNotExists
Defines the ID of the CosmosDB to which to write.
|
String |
dataType
Defines how Functions runtime should treat the parameter value.
|
String |
partitionKey
Defines the partition key path for the created collection when createIfNotExists is set to
true.
|
String |
preferredLocations
Defines preferred locations (regions) for geo-replicated database accounts in the Azure Cosmos
DB service.
|
boolean |
useMultipleWriteLocations
Enable to use with Multi Master accounts.
|
public abstract String name
public abstract String databaseName
public abstract String collectionName
public abstract String connectionStringSetting
public abstract String dataType
Defines how Functions runtime should treat the parameter value. Possible values are:
public abstract boolean createIfNotExists
public abstract String partitionKey
public abstract int collectionThroughput
public abstract boolean useMultipleWriteLocations
public abstract String preferredLocations
Copyright © 2022. All rights reserved.