What would be the best approach to implement below use case in MICRONAUT DATA mongoDB
The element collection is used to store elements of different types. Area, points, segments etc.
So for e.g. Area can have multiple childs - points, segments etc
The document will have full element details and selective child details with full hierarchy.
The child will be present in database independently as well with complete details.
Any update/delete/create to the element will require the changes to be propageted to the parent & child elements respectively.
Would we also require mapping annotation usage between parent and child?
ENTITY
@MappedEntity
public class Element{
@Id
@AutoPopulated
private UUID id;
@NotNull
private ElementType elementType;
@NotNull
private String name;
@NotNull
private PointGeoJson pointGeometry;
@Nullable
private Set<Element> associations;
... other attributes ...
}
PARENT
{
"id": "a581edd0-ee62-4b1d-b02a-5e3b68f7b234",
"elementType": "PARKING_AREA",
"name": "Area Element",
"pointGeometry": {
"type": "Point",
"coordinates": [
37.7749,
-122.4194
]
},
"associations": [
{
"id": "b581edd0-ee62-4b1d-b02a-5e3b68f7b235",
"elementType": "POINT"
},
{
"id": "c581edd0-ee62-4b1d-b02a-5e3b68f7b236",
"elementType": "POINT"
}
}
],
... other attributes ...
}
CHILD
{
"id": "b581edd0-ee62-4b1d-b02a-5e3b68f7b235",
"elementType": "POINT",
"name": "Point Element",
"pointGeometry": {
"type": "Point",
"coordinates": [
37.7749,
-122.4194
]
},
"associations": null,
... other attributes ...
}