Create Composite Key with interchangeable values

Hi !
I wanted some help in creating a composite key.
I want to create a composite key which is interchangeable, what I mean is if I have 2 keys as
key1: value1,
key2: value2
The composite key should be created such that only unique connection is formed between them.
But the value can be interchanged.
if key1 = ‘data1’ and key2 = ‘data2’ this is also equal to key1=‘data2’ and key2 = ‘data1’.

I am new to the forum and didn’t know where is the right place to ask this. Please let me know if anyone can help me with this.

Thank you!

Hi @Aisha_Deshmukh,

Not sure I fully understand the underlying requirements but what I have in mind is the following:

key : [ { "k" : "key1" , "v" : "data1" }, {"k" : "key2", "v" : "data2"}]


key : [ { "k" : "key1" , "v" : "data2" }, {"k" : "key2", "v" : "data1"}]

This way you can unique index { 'key.k' : 1, 'key.v' : 1}.

Now when you search just search key.v : … And it will find docs with that value even if the keys are interchangeable…