【问题标题】:Unable to find index for $geoNear query with @Query无法使用 @Query 找到 $geoNear 查询的索引
【发布时间】:2017-10-03 04:21:56
【问题描述】:

我在 mongo 存储库中有以下查询:

@Query("{ 'lastKnownLocation' : { $near : ?0}, 'username' : { $exists: true },
'lastActiveTime' : { $gte: ?1 }, 'id' : { $ne: ?2 }, 
$or: [ { 'hideAccountInPeopleNearby': false }, 
{ 'hideAccountInPeopleNearby': { $exists: false} } ] }")
List<Account> findTop6ByLastKnownLocationNearAndUsernameExistsAndLastActiveTimeBeforeAndId
NotAndHideAccountInPeopleNearbyFalse(Point lastKnownLocation, LocalDate lastActiveTime, 
String id);

它返回以下错误:

com.mongodb.MongoQueryException: Query failed with error code 2 and error message 'error 
processing query: ns=CloudFoundry_hj345cdo_v9ifdl8t.accountTree: $and
2017-10-02T16:25:44.91+0100 [APP/PROC/WEB/0] OUT     $or
2017-10-02T16:25:44.91+0100 [APP/PROC/WEB/0] OUT         hideAccountInPeopleNearby == false
2017-10-02T16:25:44.91+0100 [APP/PROC/WEB/0] OUT         $not
2017-10-02T16:25:44.91+0100 [APP/PROC/WEB/0] OUT             hideAccountInPeopleNearby exists
2017-10-02T16:25:44.91+0100 [APP/PROC/WEB/0] OUT     lastActiveTime $gte new Date(1506297600000)
2017-10-02T16:25:44.91+0100 [APP/PROC/WEB/0] OUT     username exists
2017-10-02T16:25:44.91+0100 [APP/PROC/WEB/0] OUT     $not
2017-10-02T16:25:44.91+0100 [APP/PROC/WEB/0] OUT         _id == ObjectId('59b8f977f75ee600121406b6')
2017-10-02T16:25:44.91+0100 [APP/PROC/WEB/0] OUT     GEONEAR  field=lastKnownLocation maxdist=1.79769e+308 isNearSphere=0
2017-10-02T16:25:44.91+0100 [APP/PROC/WEB/0] OUT Sort: {}
2017-10-02T16:25:44.91+0100 [APP/PROC/WEB/0] OUT Proj: {}
2017-10-02T16:25:44.91+0100 [APP/PROC/WEB/0] OUT  planner returned error: unable to find index for $geoNear query' on server ds059125.mlab.com:59125

这里出了什么问题?如果我删除方法上方的@Query,(并添加boolean exists 参数)它会正确返回值。但是,我需要查询能够返回 hideAccountInPeopleNearby 为 false 或 null 的值。

【问题讨论】:

    标签: spring mongodb


    【解决方案1】:

    原来解决方案只是将$near 更改为$nearSphere

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-05
      • 1970-01-01
      • 2023-04-01
      • 2015-01-06
      • 1970-01-01
      • 2017-03-24
      • 2021-10-28
      • 1970-01-01
      相关资源
      最近更新 更多