@Retention(value=RUNTIME) @Target(value=PARAMETER) public @interface CosmosDBInput
Place this on a parameter whose value would come from CosmosDB. The parameter type can be one of the following:
The following example shows a Java function that retrieves a single document. The function is triggered by an HTTP request that uses a query string to specify the ID to look up. That ID is used to retrieve a ToDoItem document from the specified database and collection. A sample URL would be like: http://localhost:7071/api/getItem?id=myid.
@FunctionName("getItem")
public String cosmosDbQueryById(
@HttpTrigger(name = "req",
methods = {HttpMethod.GET},
authLevel = AuthorizationLevel.ANONYMOUS) Optional<String> dummy,
@CosmosDBInput(name = "database",
databaseName = "ToDoList",
collectionName = "Items",
id = "{Query.id}",
connectionStringSetting = "AzureCosmosDBConnection") Optional<String> item
) {
return item.orElse("Not found");
}
| Modifier and Type | Required Element and Description |
|---|---|
String |
collectionName
Defines the collection name of the CosmosDB to which to bind.
|
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 bind.
|
String |
name
The variable name used in function.json.
|
| Modifier and Type | Optional Element and Description |
|---|---|
String |
dataType
Defines how Functions runtime should treat the parameter value.
|
String |
id
Defines the ID of the CosmosDB to which to bind.
|
String |
partitionKey
Defines partition key value for the lookup.
|
String |
sqlQuery
Defines the SQL query string to which to bind.
|
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 String id
public abstract String sqlQuery
public abstract String partitionKey
Copyright © 2022. All rights reserved.