我正在尝试通过Apache Spark在MongoDB中执行地理空间查询。 这是Java中的工作代码
BasicDBObject fields = new BasicDBObject.append(("geoid",1);
BasicDBObject queryDoc=new BasicDBObject("geometry", new BasicDBObject("$near", new BasicDBObject("$geometry", new BasicDBObject("type", "Point")
.append("coordinates", Arrays.asList(longi, lat)))
.append("$maxDistance", 100)));
查询的Json版本是:
{
geometry: {
$near: {
$geometry: {
type: "Point",
coordinates: [-87.674179, 41.97646]
},
$maxDistance: 100
}
}
}
现在,在火花中,我试图添加如下查询:
Map<String, String> mongoConfig = new HashMap<String, String>();
String query=" {\n" +
" geometry:\n" +
" {\n" +
" $near :\n" +
" {\n" +
" $geometry: { type: \"Point\", coordinates: [-87.674179, 41.97646] },\n" +
" $maxDistance: 100\n" +
" }\n" +
" }\n" +
" }";
mongoConfig.put("mongo.input.query",query);
JavaSparkContext jsc = new JavaSparkContext(session.sparkContext());
ReadConfig readConfig = ReadConfig.create(session).withOptions(mongoConfig);
但这似乎没有任何效果。 我正在检索馆藏中的所有文件。 我想念什么?