我的文档中有一个映射字段(键=内容类型,值=内容),我希望将值part(内容,这是另一个文档)保存在mongodb中作为引用对象。

private Map<ContentType, Content> relatedContents;


例如,对于内容类型“ CONTENT_TYPE_X”,应保存为


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


对于普通场,可以使用@DBREF来实现参考。

@DBRef
private Content content;


但是,当然,在这种情况下,仅通过放置@DBRef无效,是否有可能实现我所说的内容?

@DBRef
private Map<ContentType, Content> relatedContents;


非常感谢。

最佳答案

您可以完全按照spring-data-mongodb 1.3 M1版本或更高版本的建议进行操作:

@DBRef
private Map<String, Content> relatedContents;


DATAMONGO-657

关于java - 使用 Spring 数据(dbref)在mongo中映射类型字段的引用值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18933215/

10-10 08:10