Skip to content

CosmosDBOutput Unsupported PartitionKey value component '[]' #2112

@Benjiiim

Description

@Benjiiim

In a .NET 8 Isolated function (migrating from .NET 6 In-Process), I'm trying to use CosmosDBOutput to write multiple documents without knowing their types but I'm getting the following error:

System.Private.CoreLib: Exception while executing function: Functions.Function1. Microsoft.Azure.Cosmos.Client: Unsupported PartitionKey value component '[]'. Numeric, string, bool, null, Undefined are the only supported types.

Here is a repo:

using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Newtonsoft.Json;

namespace TestCosmos
{
    public class Function1
    {
        [Function("Function1")]
        [CosmosDBOutput(databaseName: "Test", containerName: "Test", CreateIfNotExists = true, PartitionKey = "/email", Connection = "cosmosConnectionString")]
        public Object[] Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req)
        {
            var input = @"[
                        {
                            ""email"": ""[email protected]"",
                            ""event"": ""processed""
                        },
                        {
                            ""email"": ""[email protected]"",
                            ""event"": ""deferred"",
                            ""category"": ""cat facts""
                        }]";

            dynamic data = JsonConvert.DeserializeObject(input);

            List<Object> outputList = new List<Object>();

            foreach(var item in data)
            {
                item.id = System.Guid.NewGuid().ToString();

                outputList.Add(item);
            }

            return outputList.ToArray();
        }
    }
}

Am I doing anything wrong?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions