I have two collections: vehicles and setters
Setters
A setter document has two main fields: conditions and result. It’s used to store some rules like “if Category = d10 and Brand = BMW then isTransportable = false”. The way we store this in the setters collections is :
{
"conditions": {
"category": "d10",
"brand": "BMW"
},
"result": {
"isTransportable": false
}
}
Another example: “if brand = Ferrari then isPricey = true” is stored
{
"conditions": {
"brand": "Ferrari"
},
"result": {
"isPricey": true
}
}
Remarks:
- A setter can have multiple conditions but always have one result (i.e. the subdocument “result” will always have one single field).
- The fields that are used in the result does never appear in conditions. There is no setter document for which
isPricey
orisTransportable
is used as a condition. And vice-versa, the fields used in conditions are never used in the result. There is no setter document for which brand is a result. Fields appearing in conditions and fields appearing in result are two completely disjoint fields.
Vehicles:
A vehicle document has a flat structure, is has the fields Category, brand, isTransportable, isPricey.
What I am trying to do
I want to update the values of vehicles according to the rules.
If I have a vehicle that have “category” =“d10” and “brand” =“BMW”, I want to update its isTransportable value using the result of the setter document:
{
"conditions": {
"category": "d10",
"brand": "BMW"
},
"result": {
"isTransportable": false
}
}
So it will be set the vehicle will have isTransportable equal to false…
However, if my vehicle have category = “d10” and brand != “bmw” then I will not use that rule.
Is there a way to do this using the aggregates, without having to fetch vehicles and setters