邮递员(和 python 前夕)在 mongodb 中完成时为同一查询提供不同的结果
Postman (and python eve) providing different results to same query when done in mongodb
我正在使用 python eve 开发一个非常轻量级的 API,它访问 mongodb 数据库。数据库中的每个文档都有一个 geom 字段,并且该字段上有一个二维球体索引。
当我在 mongo 中 运行 这个查询时,它运行得非常好而且非常快
db.api.aggregate({"$geoNear": {"near": {"type": "Point", "coordinates": [-1.11, 51.69]}, "distanceField": "distance", "maxDistance": 100, "num": 2, "spherical": "true"}}).pretty()
但是当我在邮递员中 运行 它只是 returns 一切并忽略查询
http://localhost:8090/data?aggregate={"$geoNear": {"near": {"type": "Point", "coordinates": [-1.11, 51.69]}, "distanceField": "distance", "maxDistance": 100,"num": 2,"spherical": "true"}}
我在 Eve 中设置了一个基本模式,它部分有效。 returns 只有 _id 而不是作为查询的一部分创建的距离字段。尽管我 运行 假设一旦我的邮递员语法正确,这就会起作用。
api_shema = {'_id': {'type': 'string'},
'distance': {'type': 'string'}
}
我也设置了这个项目
line_info_item = {'item_title': 'line_info',
'resource_methods': ['GET'],
'schema': api_shema,
'datasource': {
'source': 'api',
'filter': {'_type': 'line'}
}
}
终于添加了以下域名
DOMAIN = {'line_info': line_info_item}
任何有关邮递员查询的帮助,或者如果您发现其余部分有任何错误,我们将不胜感激。
编辑:
我按照下面 Neil 的回答在端点上设置了管道,但它仍然忽略查询并返回所有内容。
DOMAIN = {'line_info': line_info_item,
'aggregation': {
'pipeline': [{
"$geoNear": {
"near": {
"type": "Point",
"coordinates": ["$coords"]
},
"distanceField": "distance",
"maxDistance": "$maxDist",
"num": 10,
"spherical": "true"
}
}]
}
}
邮递员查询url是
http://localhost:8090/data?aggregate={"$maxDist":500, "$coords":[-1.477307, 50.931700]}
编辑
有点工作,虽然忽略了架构......但我猜这是一个不同的问题。
将聚合管道移动到项目中并删除了“$coords”周围的方括号
river_relate_item = {'item_title': 'line_info_item',
'resource_methods': ['GET'],
'schema': api_shema,
'datasource': {
'source': 'api',
'filter': {'_type': 'line'},
'aggregation': {'pipeline': [{'$geoNear':{'near':{'type': 'point', 'coordinates': '$coords'},'distanceField': 'distance','maxDistance': '$maxDist','num': 1, 'spherical': 'true'}}]}
},
}
有点工作,虽然忽略了架构...但我猜这是一个不同的问题。
将聚合管道移动到项目中并删除了“$coords”周围的方括号
river_relate_item = {'item_title': 'line_info_item',
'resource_methods': ['GET'],
'schema': api_shema,
'datasource': {
'source': 'api',
'filter': {'_type': 'line'},
'aggregation': {'pipeline': [{'$geoNear':{'near':{'type': 'point', 'coordinates': '$coords'},'distanceField': 'distance','maxDistance': '$maxDist','num': 1, 'spherical': 'true'}}]}
},
}
我正在使用 python eve 开发一个非常轻量级的 API,它访问 mongodb 数据库。数据库中的每个文档都有一个 geom 字段,并且该字段上有一个二维球体索引。
当我在 mongo 中 运行 这个查询时,它运行得非常好而且非常快
db.api.aggregate({"$geoNear": {"near": {"type": "Point", "coordinates": [-1.11, 51.69]}, "distanceField": "distance", "maxDistance": 100, "num": 2, "spherical": "true"}}).pretty()
但是当我在邮递员中 运行 它只是 returns 一切并忽略查询
http://localhost:8090/data?aggregate={"$geoNear": {"near": {"type": "Point", "coordinates": [-1.11, 51.69]}, "distanceField": "distance", "maxDistance": 100,"num": 2,"spherical": "true"}}
我在 Eve 中设置了一个基本模式,它部分有效。 returns 只有 _id 而不是作为查询的一部分创建的距离字段。尽管我 运行 假设一旦我的邮递员语法正确,这就会起作用。
api_shema = {'_id': {'type': 'string'},
'distance': {'type': 'string'}
}
我也设置了这个项目
line_info_item = {'item_title': 'line_info',
'resource_methods': ['GET'],
'schema': api_shema,
'datasource': {
'source': 'api',
'filter': {'_type': 'line'}
}
}
终于添加了以下域名
DOMAIN = {'line_info': line_info_item}
任何有关邮递员查询的帮助,或者如果您发现其余部分有任何错误,我们将不胜感激。
编辑:
我按照下面 Neil 的回答在端点上设置了管道,但它仍然忽略查询并返回所有内容。
DOMAIN = {'line_info': line_info_item,
'aggregation': {
'pipeline': [{
"$geoNear": {
"near": {
"type": "Point",
"coordinates": ["$coords"]
},
"distanceField": "distance",
"maxDistance": "$maxDist",
"num": 10,
"spherical": "true"
}
}]
}
}
邮递员查询url是
http://localhost:8090/data?aggregate={"$maxDist":500, "$coords":[-1.477307, 50.931700]}
编辑
有点工作,虽然忽略了架构......但我猜这是一个不同的问题。
将聚合管道移动到项目中并删除了“$coords”周围的方括号
river_relate_item = {'item_title': 'line_info_item',
'resource_methods': ['GET'],
'schema': api_shema,
'datasource': {
'source': 'api',
'filter': {'_type': 'line'},
'aggregation': {'pipeline': [{'$geoNear':{'near':{'type': 'point', 'coordinates': '$coords'},'distanceField': 'distance','maxDistance': '$maxDist','num': 1, 'spherical': 'true'}}]}
},
}
有点工作,虽然忽略了架构...但我猜这是一个不同的问题。
将聚合管道移动到项目中并删除了“$coords”周围的方括号
river_relate_item = {'item_title': 'line_info_item',
'resource_methods': ['GET'],
'schema': api_shema,
'datasource': {
'source': 'api',
'filter': {'_type': 'line'},
'aggregation': {'pipeline': [{'$geoNear':{'near':{'type': 'point', 'coordinates': '$coords'},'distanceField': 'distance','maxDistance': '$maxDist','num': 1, 'spherical': 'true'}}]}
},
}