Annotation Type CosmosDBInput


  • @Retention(RUNTIME)
    @Target(PARAMETER)
    public @interface CosmosDBInput

    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<T>
    • 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 container. 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",
                          containerName = "Items",
                          id = "{Query.id}",
                          connection = "AzureCosmosDBConnection") Optional<String> item
     ) {
         return item.orElse("Not found");
     }
     
    Since:
    1.0.0
    • Required Element Summary

      Required Elements 
      Modifier and Type Required Element Description
      java.lang.String connection
      Defines the app setting name that contains the CosmosDB connection string.
      java.lang.String containerName
      Defines the container name of the CosmosDB to which to bind.
      java.lang.String databaseName
      Defines the database name of the CosmosDB to which to bind.
      java.lang.String name
      The variable name used in function.json.
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      java.lang.String dataType
      Defines how Functions runtime should treat the parameter value.
      java.lang.String id
      Defines the ID of the CosmosDB to which to bind.
      java.lang.String partitionKey
      Defines partition key value for the lookup.
      java.lang.String sqlQuery
      Defines the SQL query string to which to bind.
    • Element Detail

      • name

        java.lang.String name
        The variable name used in function.json.
        Returns:
        The variable name used in function.json.
      • databaseName

        java.lang.String databaseName
        Defines the database name of the CosmosDB to which to bind.
        Returns:
        The database name string.
      • containerName

        java.lang.String containerName
        Defines the container name of the CosmosDB to which to bind.
        Returns:
        The container name string.
      • connection

        java.lang.String connection
        Defines the app setting name that contains the CosmosDB connection string.
        Returns:
        The app setting name of the connection string.
      • dataType

        java.lang.String dataType

        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[]
        Returns:
        The dataType which will be used by the Functions runtime.
        Default:
        ""
      • id

        java.lang.String id
        Defines the ID of the CosmosDB to which to bind.
        Returns:
        The ID string.
        Default:
        ""
      • sqlQuery

        java.lang.String sqlQuery
        Defines the SQL query string to which to bind.
        Returns:
        The SQL query string.
        Default:
        ""
      • partitionKey

        java.lang.String partitionKey
        Defines partition key value for the lookup. May include binding parameters.
        Returns:
        partition key value
        Default:
        ""