CosmosDBInput Interface


Place this on a parameter whose value would come from CosmosDB. The parameter type can be one of the following:

  • Some native Java types such as String
  • Nullable values using Optional
  • Any POJO type

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.

 public String cosmosDbQueryById(
    @HttpTrigger(name = "req",
                  methods = {HttpMethod.GET},
                  authLevel = AuthorizationLevel.ANONYMOUS) Optional<String> dummy,
    @CosmosDBInput(name = "database",
                      databaseName = "ToDoList",
                      collectionName = "Items",
                      id = "{}",
                      connectionStringSetting = "AzureCosmosDBConnection") Optional<String> item
 ) {
     return item.orElse("Not found");
public interface CosmosDBInput implements Annotation



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


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


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

  • "": get the value as a string, and try to deserialize to actual parameter type like POJO
  • string: always get the value as a string
  • binary: get the value as a binary data, and try to deserialize to actual parameter type byte[]

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


Defines the ID of the CosmosDB to which to bind.


The variable name used in function.json.


Defines partition key value for the lookup. May include binding parameters.


Defines the SQL query string to which to bind.

Applies to