Custom Type Mapping in MongoDB

Let me start by saying that my goal is to achieve the fastest read operations that I can, so if you notice something in your code / description that could help me with this, let me know.

I have only a web reader for reading that pulls objects from MongoDB. However, the response object that I will return to the user will not need all the data. Since it is standing right now, the process is as follows:

  • Get info from mongo
  • Match this information with an object
  • Use access methods to pass values ​​from the specified object to the response object.
  • Return the response object to the user.

I would like to combine steps 1 and 2, just having the data coming out of the mongo, directly mapped to the response object.

I dug up DefaultMongoTypeMapperall the classes that he uses, but I wrap my head a lot before I'm sure this is the right direction.

In addition to what I have listed above, I have a few more problems. One of them is that the objects stored in Mongo do not have a field _class, since they are raw data (from what I saw, the mapper type uses this field to determine the class to map to). The surface of this is that everything coming out of the database will be mapped to the same object, so we can guess which class to use.

Has anyone done something like this, is the past or any suggestions as to how this can be done?

Great importance.

+4
1

, , , , MongoDB. Java ( ) % . , , MongoDB (, , , , ..).

java , . java, , , . , , .

POJO ? . ODM, morphia https://code.google.com/p/morphia/

/ Spring ( ) : http://projects.spring.io/spring-data-mongodb/, : http://spring.io/guides/gs/accessing-data-mongo/

+4

All Articles