Hello all,
Short intro for my question:
In our product we have a Step
object that identify a specific step inside a bigger Run.
Step is identified uniquely by 3 fields : run_id, step_name(string), scopes(array).
So here is the thing - “scopes” is an array that describes the scope of the specific step.
These 2 objects are should be able to live together:
# A lives under "x" scope
{
run_id: 123,
step_name: "A",
scopes: [x:{<x_details>}]
}
# A lives under "x" and specific "y" scope.
{
run_id: 123,
step_name: "A",
scopes: [{"x": <x_data>}, {"y": <y1_data>} ]
}
# A lives under "x" and a specific (defferent y) "y" scope.
{
run_id: 123,
step_name: "A",
scopes: [{"x": <x_data>}, {"y": <y2_data>} ]
}
My question: I need my index to be unique by the 3 keys - run_id, step_name, scopes ,
BUT mongodb will raise a WriteError (code=11000 "dup key" )
when trying to insert any 2 of the 3 in the exmaple, when the collection is indexed with unique=True
.
How can I get the effect I want ?
Thank you in advance.