Can someone please help me with creation of unique index @ mongoDB for the following condition ?
Suppose I have a schema like this, and I want a unique compound index on 1.path 2.verb 3."switches.name" 4."switches.value"
{
"path": "somepath",
"verb": "GET",
"switches": [
{
"name": "id",
"value":"123"
},
{
"name": "age",
"value":"25"
}
]
}
So if I try to insert
{
"path": "somepath",
"verb": "GET",
"switches": [
{
"name": "id",
"value":"123"
},
{
"name": "age",
"value":"25"
}
]
}
I should get duplicate error, but if I insert
{
"path": "somepath",
"verb": "GET",
"switches": [
{
"name": "id",
"value":"123"
},
{
"name": "age",
"value":"24"
}
]
}
or
{
"path": "somepath",
"verb": "GET",
"switches": [
{
"name": "id",
"value":"123"
},
{
"name": "age",
"value":"25"
},
{
"name": "foo",
"value":"bar"
}
]
}
I shouldn't get any error.
Basically, I should be allowed to insert documents with distinct array "switches".