filter几何查询附近的环回

我试图得到一个半径范围内的用户(Cronies)。 我正在使用mongodb + loopback,并可以通过远程方法成功查询位置。

然而,当我尝试通过api资源pipe理器提供附近的where参数时,我得到一个错误,如下所示:

参数提供为“where”:

{"last_location": {"near": [-33.8670522,151.1957362]}, "maxDistance":1} 

请求url:

http://localhost:3000/api/Cronies/count?where=%7B%22last_location%22%3A%20%7B%22near%22%3A%20%5B-33.8670522%2C151.1957362%5D%7D%2C%20%22maxDistance%22%3A1%7D&access_token=AYlOjRtu77JWNywHVMtRqEAZfLzKNyq2OFV31ZKHaUSQBNZojxSJb9Q5QI7RjAXc

错误:

 { "error": { "name": "MongoError", "status": 500, "message": "error processing query: ns=fresh.Crony limit=0 skip=0\nTree: $and\n maxDistance == 1\n GEONEAR field=last_location maxdist=1.79769e+308 isNearSphere=0\nSort: {}\nProj: {}\n planner returned error: unable to find index for $geoNear query", "ok": 0, "errmsg": "error processing query: ns=fresh.Crony limit=0 skip=0\nTree: $and\n maxDistance == 1\n GEONEAR field=last_location maxdist=1.79769e+308 isNearSphere=0\nSort: {}\nProj: {}\n planner returned error: unable to find index for $geoNear query", "code": 2, "stack": "MongoError: error processing query: ns=fresh.Crony limit=0 skip=0\nTree: $and\n maxDistance == 1\n GEONEAR field=last_location maxdist=1.79769e+308 isNearSphere=0\nSort: {}\nProj: {}\n planner returned error: unable to find index for $geoNear query\n at Function.MongoError.create (/Users/alex/dev/crony/crony-backend/node_modules/loopback-connector-mongodb/node_modules/mongodb/node_modules/mongodb-core/lib/error.js:31:11)\n at /Users/alex/dev/crony/crony-backend/node_modules/loopback-connector-mongodb/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:754:66\n at /Users/alex/dev/crony/crony-backend/node_modules/loopback/node_modules/continuation-local-storage/context.js:74:17\n at bound (domain.js:250:14)\n at runBound (domain.js:263:12)\n at Callbacks.emit (/Users/alex/dev/crony/crony-backend/node_modules/loopback-connector-mongodb/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:95:3)\n at null.messageHandler (/Users/alex/dev/crony/crony-backend/node_modules/loopback-connector-mongodb/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:243:23)\n at Socket.<anonymous> (/Users/alex/dev/crony/crony-backend/node_modules/loopback-connector-mongodb/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:262:22)\n at emitOne (events.js:77:13)\n at Socket.emit (events.js:169:7)" } } 

我认为你不会生成索引列,这很简单,只需连接你的mongo shell并使用:

 db.<collection>.ensureIndex({point:"2dsphere"}) 

来源:看看链接

我有同样的问题,答案为我工作。