[英]How to get All unstructured fields of MongoDB using Morphia
I have some data stored in MongoDb, that currently I do not want to map on POJO, How we can get all unstructured fields of Documents in a single map. 我有一些数据存储在MongoDb中,目前我不希望在POJO上进行映射。如何在单个映射中获取Documents的所有非结构化字段。
I found this link 我找到了这个链接
http://www.carfey.com/blog/using-mongodb-with-morphia/ http://www.carfey.com/blog/using-mongodb-with-morphia/
that says you can mapped all unstructured fields using 那表示您可以使用以下方式映射所有非结构化字段
// .. our base attributes here
private Map<String, Object> attributes
but its not working as I am contiguously getting it null, I checked the Morphia code, It iterates on Morphia entity class fields, so how can we get all DBObject unmapped fields in attributes Map. 但是它不能正常工作,因为我一直在使它为null,所以我检查了Morphia代码,它在Morphia实体类字段上进行迭代,因此如何在属性Map中获取所有DBObject未映射的字段。
Out of interest: Why would you do that? 出于兴趣:您为什么要这样做? You'll need to map the class and the one field, in which you want to add your data, to Morphia anyway.
无论如何,您都需要将类和要在其中添加数据的一个字段映射到Morphia。 Or am I misunderstanding you?
还是我误会你了?
How to do it: You'll need to annotate all fields you want to store in the map with @Transient
and add / load them in your custom @PrePersist
and @PostLoad
methods. 操作方法:您需要使用
@Transient
注释要存储在地图中的所有字段,并在自定义@PrePersist
和@PostLoad
方法中添加/加载它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.