我试图在半径内获得用户(密友)的计数。我使用mongodb +环回,可以通过远程方法成功地按位置查询。
然而,当我试图通过api资源管理器在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=0nTree: $andn maxDistance == 1n GEONEAR field=last_location maxdist=1.79769e+308 isNearSphere=0nSort: {}nProj: {}n planner returned error: unable to find index for $geoNear query",
"ok": 0,
"errmsg": "error processing query: ns=fresh.Crony limit=0 skip=0nTree: $andn maxDistance == 1n GEONEAR field=last_location maxdist=1.79769e+308 isNearSphere=0nSort: {}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=0nTree: $andn maxDistance == 1n GEONEAR field=last_location maxdist=1.79769e+308 isNearSphere=0nSort: {}nProj: {}n planner returned error: unable to find index for $geoNear queryn 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:66n at /Users/alex/dev/crony/crony-backend/node_modules/loopback/node_modules/continuation-local-storage/context.js:74:17n 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"})
来源:看那个链接
我也遇到过同样的问题,这个答案对我很有用。