Annotation Type CosmosDBOutput


  • @Retention(RUNTIME)
    @Target({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:

    • 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", containerName = "Items",
        connection = "AzureCosmosDBConnection")
     ) {
         return "{ \"id\": \"" + System.currentTimeMillis() + "\", \"description\": \"" + message + "\" }";
     }
     
    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 write.
      java.lang.String databaseName
      Defines the database name of the CosmosDB to which to write.
      java.lang.String name
      The variable name used in function.json.
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      int containerThroughput
      If CreateIfNotExists is true, defines the throughput of the created container.
      boolean createIfNotExists
      Defines the ID of the CosmosDB to which to write.
      java.lang.String dataType
      Defines how Functions runtime should treat the parameter value.
      java.lang.String partitionKey
      Defines the partition key path for the created container when createIfNotExists is set to true.
      java.lang.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.
    • 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 write.
        Returns:
        The database name string.
      • containerName

        java.lang.String containerName
        Defines the container name of the CosmosDB to which to write.
        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:

        • "" 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.
        Default:
        ""
      • createIfNotExists

        boolean createIfNotExists
        Defines the ID of the CosmosDB to which to write.
        Returns:
        The ID string.
        Default:
        false
      • partitionKey

        java.lang.String partitionKey
        Defines the partition key path for the created container when createIfNotExists is set to true. May include binding parameters.
        Returns:
        partitionKey of the created container.
        Default:
        ""
      • containerThroughput

        int containerThroughput
        If CreateIfNotExists is true, defines the throughput of the created container.
        Returns:
        Throughput of the created container.
        Default:
        -1
      • useMultipleWriteLocations

        boolean useMultipleWriteLocations
        Enable to use with Multi Master accounts.
        Returns:
        whether to Multi Master accounts
        Default:
        false
      • preferredLocations

        java.lang.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
        Default:
        ""