0
votes

Sometimes you just want to make a native query and make Morphia map it nicely. I made it work using:

BasicDBObject parse = BasicDBObject.parse("{location:{$near:{$geometry:{type: 'Point', coordinates: ["+ location[0]+","+location[1]+"]}, $maxDistance: "+ maxDistance+"}}}");
Query<LabDataDTO> query = ((AdvancedDatastore) MorphiaHandler.getStore()).createQuery(LabDataDTO.class, new Document(parse));

... but its not very pretty, uses casting and uses deprecated methods - How do you do that nicely in Morphia 2.0?

1

1 Answers

0
votes

Honestly, it's a feature that I explicitly killed (at least as implemented) in the transition from 1.x to 2.x because it exposed/used certain internal implementation details and would break people if I ever changed anything in those areas. It can probably be safely reintroduced with a Datastore#find(Class type, Document query) method now that I have some safeguards around documenting what is and isn't safe to use. If that's something you really need, please file an issue and we can work toward a solution.