Array Add Unique complex poco

Is it possible to use the sub document api to add unique complex objects to an array.

By complex object I mean a poco class that has properties of it’s own such as dictionaries and other arrays.

What will the performance considerations be?

Hi @ftaran

It is possible to store POCOs in unique arrays using the SubDoc API, however it is not recommended because the only way to determine uniqueness on the server is via string comparison. This is adequate for primitive types, but less useful for custom types.

@MikeGoldsmith I tried using ArrayAddUnique with a complex object:

var mutation = _bucket.MutateIn<PaymentStateDocument>(command.CorrelationId.ToString())
                .ArrayAddUnique(nameof(PaymentStateDocument.Commands), command)

            var result = await mutation.ExecuteAsync();

but I get the following error:

KV Error: {Name="SUBDOC_VALUE_CANTINSERT", Description="Subdoc: Value invalid for insertion", Attributes="subdoc,invalid-input"}

any idea why this is happening?

What you are trying to store would not create valid JSON.