Question: I am using a User Defined Function across multiple collections within multiple Cosmos databases. Is there a way to store it somewhere and deploy it to all of these collections/databases at once? Or a way to update them all at the same time? Currently I am having to go through and manually update each UDF within each collection within each database.

Answer: 
You can write console application for updating UDF-

```
        private async Task<string> CreateUDFAsync(string collectionUri, string udfName, string udfBody)
    {
        ResourceResponse<UserDefinedFunction> response = null;

        try
        {
            var existingUdf = await this.cosmosDbClient.ReadUserDefinedFunctionAsync($"{collectionUri}/udfs/{udfName}");

            existingUdf.Resource.Body = udfBody;

            response = await this.cosmosDbClient.ReplaceUserDefinedFunctionAsync(existingUdf.Resource);

        }
        catch (DocumentClientException ex)
        {
            response = await this.cosmosDbClient.CreateUserDefinedFunctionAsync(collectionUri,
               new UserDefinedFunction
               {
                   Id = udfName,
                   Body = udfBody
               });
        }

        return response.Resource.AltLink;
    }

```

It will replace existing UDF and Create new in case missing
At the Cosmos DB resource model structure stored procedures, UDFs, merge procedures, triggers and conflicts are Container level resources.

![](https://learn.microsoft.com/en-us/azure/cosmos-db/media/databases-containers-items/cosmos-entities.png)

You have to create them for each container.