Is it possible to create a unique index in MonboDB over an entire Set lets say UserId's?
Example code
@Indexed
val participantIds: Set<UserId>
Such that, the entire Set is unique. This combination only exists once.
Example
[1, 2] // OK
[2, 3] // OK
[2, 1] // NOT OK (combination exists already)
UPDATE
The use case is for a messaging system. The participantIds are the members of that single or group messenger.
After reading the answers, I feel checking it in the e.g. Service Layer might be my use case with a $all / $size query check to verify that such combination does not exist.