Arangodb:按时间戳和坐标过滤的自行车

Arangodb: bikes filtered by timestamp and coordinates

我有这样的数据结构:

红色顶点位置 青色顶点是 BIKE 粉色顶点是 USER

GRAPH TD

((BIKE)) -- LOCATED -->((POSITION))

其中 BIKE 是一个与许多 POSITION 关联的

每个位置都有经纬度属性和时间戳

我想找到距离坐标对 40Km 附近且不超过 48 小时的所有自行车

我目前所做的是:

FOR pos IN NEAR(positions, 45.5063575, 9.24157653499384, 40, "distance")
        FILTER pos.timestamp >= DATE_SUBTRACT(DATE_NOW(), "PT48H")
        SORT pos.timestamp DESC, pos.distance DESC
        RETURN {'position': pos,'bike':(FOR bike IN OUTBOUND pos located RETURN  bike)}

但是这个查询返回了他们自行车的所有位置,我想要最后一个位置(最近的时间)和所属的自行车

感谢您的帮助

你需要这样的东西:

FOR pos IN WITHIN(positions, 45.5063575, 9.24157653499384, 40, "distance")
  FILTER pos.timestamp >= DATE_SUBTRACT(DATE_NOW(), "PT48H")
  SORT pos.timestamp DESC
  FOR b IN OUTBOUND pos located
    COLLECT bike = b INTO bike_positions
    RETURN {'bike': bike, 'position': bike_positions[0].pos}

注意:您应该使用WITHIN而不是NEAR

更新 @Loki 评论后:

FOR pos IN positions
  FILTER pos.timestamp >= DATE_SUBTRACT(DATE_NOW(), "PT200H") AND 
         GEO_DISTANCE([45.47942614827045, 9.24157653499384], pos.coordinates)
  SORT pos.timestamp DESC     
  FOR b IN OUTBOUND pos located
    COLLECT bike = b INTO bike_positions
    RETURN {'bike': bike, 'position': bike_positions[0].pos}