java mongodb查询附近

时间:2019-02-27 12:40:07

标签: mongodb spring-mongodb spring-mongo

用户集合:

:

Java查询:

"userID":"1",
"location" : [ 
        77.667248, 
        13.0258562
    ],
 "latlong" : {
        "type" : "point",
        "coordinates" : [ 
            77.667248, 
            13.0258562
        ]
    },

我正在使用两个以上的Java查询来获取附近的用户,但在下面得到了这样的异常。我也在用户集合上创建了2dsphere索引。

例外:

 Query mongoQuery1 = new Query();
            mongoQuery1.addCriteria(Criteria.where("latlong.coordinates").near(point));
            mongoTemplate.find(mongoQuery1, User.class,"places");


  Query mongoQuery2 = new Query();
            mongoQuery2.addCriteria(Criteria.where("location").near(point));
            mongoTemplate.find(mongoQuery2, User.class,"places");

此时将用户对象插入集合中时,我遇到了相同的异常

org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [org.springframework.data.geo.Point] to type [org.bson.Document]
    at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:321)
    at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:194)

请帮助我。谢谢。

0 个答案:

没有答案