gpt4 book ai didi

java - Filters.geoIntersects 从 Java 应用程序不返回任何内容,而 Robo 3T 的查询返回一些

转载 作者:行者123 更新时间:2023-12-01 19:09:28 24 4
gpt4 key购买 nike

我有一个使用 MongoDb 的 Java 应用程序(客户端版本 3.12)。Filters.geoIntersects 从 Java 应用程序不返回任何内容从 Robo 3T 查询相同的数据时会返回一些数据,这里是 Java 和脚本的代码。我的 Java 代码出了什么问题。我错过了什么吗?如有任何帮助,我们将不胜感激。

谢谢

奥斯汀

// Using script in Robo 3T ==> returns a few records
db.getCollection('locations').find( {
place: {
$geoIntersects: {
$geometry: {
type: "Point" ,
coordinates:
[131.005440819316, 33.7843715591825 ]
}
}
}
}
)

// Java code returns nothing
collection = db.getCollection("locations");
Point curPos = new Point(new Position(131.005440819316, 33.7843715591825));
collection.find(Filters.geoIntersects("place.coordinates", curPos))
.forEach(new Consumer<Document>() {
@Override
public void accept(Document t) {
logger.info( t.toJson());
}
});

最佳答案

MongoDB 驱动程序期望文档必须有一个名为“坐标”的字段。因此解决方法是从查询中删除坐标字段。

  collection = db.getCollection("locations");
Point curPos = new Point(new Position(131.005440819316, 33.7843715591825));
collection.find(Filters.geoIntersects("place", curPos))
.forEach(new Consumer<Document>() {
@Override
public void accept(Document t) {
logger.info( t.toJson());
}
});
``

关于java - Filters.geoIntersects 从 Java 应用程序不返回任何内容,而 Robo 3T 的查询返回一些,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59493992/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com