Question

I have a map field in my document (key = content type, value = content) where I want the value part(content, which is another document) to be saved in mongodb as a referenced object.

private Map<ContentType, Content> relatedContents;

For example, for a content type, "CONTENT_TYPE_X", it should save like

"relatedContents" : { "CONTENT_TYPE_X" : DBRef("content", ObjectId("51ea2c0167e855d6b3d3dda3") }

For a normal field reference can be achieved using @DBREF , eg.

@DBRef
private Content content;

But of course it doesn't work in this case by just putting @DBRef , is it somehow possible to achieve what I am saying?

@DBRef
private Map<ContentType, Content> relatedContents;

Many Thanks.

Was it helpful?

Solution

You can do it exactly as you propose with spring-data-mongodb version 1.3 M1 or later:

@DBRef
private Map<String, Content> relatedContents;

see DATAMONGO-657

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top