Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring-MongoDB geonear not working with extra fields
    primarykey
    data
    text
    <p>I have some geospatial data in MongoDB and I want to find list of places which are near User's location and match certain criteria.</p> <p>Here is my document structure:</p> <pre><code>{ "_id" : { "$oid" : "528af043d1a2760efcd2fd2f" }, "city" : "Miami", "name" : "Some Place", "tickets" : 61, "zipcode" : "33142", "type" : "amusement park", "state" : "FL", "location" : [ -80.24, 25.8092 ]} { "_id" : { "$oid" : "528af043d1a2760efcd2fd30" }, "city" : "Miami", "name" : "Other place", "tickets" : 15, "zipcode" : "33150", "type" : "theatre", "state" : "FL", "location" : [ -80.2094, 25.8587 ]} </code></pre> <p>Now I am trying to find places through latitude, longitude, which have tickets available and are of certain kind. When I just use NearQuery with coordinates (without adding query), I am getting results, but when I add query object I am getting empty list.</p> <p>Here is my code:</p> <pre><code>public GeoResults&lt;Place&gt; find(double lat, double lon, int tickets, String type) { Point point = new Point(lon, lat); Query query = new Query(Criteria.where("tickets").gt(tickets). and("type").is(type)); NearQuery nearQuery = NearQuery.near(point).maxDistance(new Distance(10, Metrics.KILOMETERS)); nearQuery.query(query); GeoResults&lt;Place&gt; repoData = repo.findByLocationNear(point, new Distance(10, Metrics.KILOMETERS)); GeoResults&lt;Place&gt; data = mongoTemplate.geoNear(nearQuery, Place.class); List&lt;Place&gt; testData = mongoTemplate.find(query, Place.class); return data; } </code></pre> <p>From above code, GeoResults data has no contents while List testData returns proper results(but does not uses spatial information). If I use repository, I can get list of places but that does not takes additional parameters into consideration.</p> <p>Thanks in Advance</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload