Why Doesn't the mva Unique Constraint Prevent Duplicate Values in an Array Field?

I have in my User collection an field array called emails where I added an mva unique constraint. As my understanding about mva() in the context of unique that it creates a separate index entry for each value in the array so it should avoid having the same string multiple times. Leading to, that this should not work:

emails: [
    "john@doe.com",
    "john@doe.com"
  ]

I expected to get a unique constraint error, but surprisingly this is working. What am I missing here?

collection User {
    firstName: String
    lastName: String
    primaryEmail: String
    emails: Array<String>
    compute emailVerification: String? = doc => { getVerificationEmail(doc.id)}
    avatar: String?
    accounts: Array<Ref<Account>>

    unique [mva(.emails)]
    unique [mva(.accounts)]
}

Great question! A unique constraint guarantees that no other document has the same combination of terms.

To check that every item in the array is unique, you can add a check constraint

check unique_emails (user => user.emails.length == user.emails.distinct().length)

We’re working on documenting this more clearly and including the workaround pattern.

Ok, so the unique constraint is only working between different documents, but not the same document.
So Example 1 and 2 will throw an error, but 3 won’t. That means, for example 3 we need your mentioned workaround.
Is that intended, or do you plan to fix this behavior so that the unique constraint also works in the same document array?

Example 1

// document 1
emails: [
    "john@doe.com",
    "mark@tailor.com"
]

// document 2
emails: [
    "john@doe.com",
    "mark@tailor.com"
]
// => 

Example 2

// document 1
emails: [
    "john@doe.com",
    "mark@tailor.com"
]

// document 2
emails: [
    "john@doe.com"
]

Example 3

// document 1
emails: [
    "john@doe.com"
]

// document 2
emails: [
    "mark@tailor.com",
    "mark@tailor.com"
]

Hi! Sorry for not being more precise before. The behavior is expected: that your Example 3 will NOT throw a constraint failure for the unique [.emails] configuration. There are no plans to change this behavior. An explicit check constraint is the recommended method to enforce that all items in your array are distinct.