Question

Lets Say I have table named Person as follows:

class Person{
    ObjectId id;
    String name;
    @Reference
    Address adr;
}
class Address{
    Position pos;
}
class Position{
    double longitude;
    double latitude;
}

how can I return all the persons in a sphere? the query for a sphere is:

DBObject queryOnVenue = QueryBuilder.start("pos").withinCenterSphere(longitude, latitude, radiusInMeters / HandlersConfiguration.EARTH_RADIUS).get();
Était-ce utile?

La solution

What you have there isn't a nested field in mongo. Address is stored in its own collection and a reference is stored in the person collection containing that address's id. So, in essence, there is no nested field pos under person. What you're trying to do there is an implicit join and mongodb doesn't support joins. Your two solutions (there are probably others) is to do two queries (1 to find the addresses and another to find those users) or use @Embedded on Address there so that the Address document would be embedded in the Person document stored in mongodb. If you go with option 2, you could reference that field with address.pos in your query.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top