Reputation: 1370
I've the following mongodb document:
{
"_id" : ObjectId("57a068b13a4b500d7f2c72a2"),
"results" : [
{
"position" : NumberInt(12),
"product" : DBRef("product", ObjectId("579f92cfcb22890ba7b0ae15"))
}
]
}
How can i map this document correctly to a spring boot domain/model class using spring-data-mongodb?
Using the following attribute in the model works but i think it's not clear enough because i've to ensure that the object in the map is an objectId or DBRef.
private List<Map<String, Object>> results;
Also creating a separate result model and using private List<Result> results;
didn't work.
Upvotes: 3
Views: 655
Reputation: 83131
Something roughly equivalent to this should do the trick:
class MyDocument {
ObjectID id;
List<Result> results;
…
}
class Result {
int position;
@DBRef Product product;
…
}
class Product {
ObjectId id;
}
The important bits:
@DBRef
ObjectId
as identifier typeUpvotes: 3