如何在 Flask App 中从 Pymongo 过滤 MongoDB 数据库?
How can I filter MongoDB Database from Pymongo in Flask App?
我正在尝试查询我的数据库,将字符串作为参数传递。几天前它工作,但突然它停止工作。是不是我漏了什么?
class Hotel(Resource):
def get(self, cityName):
docs_list = list(client['mongodbhotels']['wheather_conditions'].find(
filter = {
'name': { "$eq" : cityName}
},
allow_partial_results = True )
)
json_response = json.dumps(docs_list, default=json_util.default)
return json.loads(json_response)
api.add_resource(HotelList, '/')
api.add_resource(Hotel, '/<string:cityName>')
if __name__ == '__main__':
app.run(debug=True)
我希望使用我的参数(城市名称)得到这样的 url
http://127.0.0.1:5000/Madrid
这个查询是有效的,但现在它returns一个空值
你试过吗?
class Hotel(Resource):
def get(self, cityName):
docs_list = list(client['mongodbhotels']['wheather_conditions'].find(
filter = {
'name': cityName
},
allow_partial_results = True )
)
json_response = json.dumps(docs_list, default=json_util.default)
return json.loads(json_response)
api.add_resource(HotelList, '/')
api.add_resource(Hotel, '/<string:cityName>')
if __name__ == '__main__':
app.run(debug=True)```
我正在尝试查询我的数据库,将字符串作为参数传递。几天前它工作,但突然它停止工作。是不是我漏了什么?
class Hotel(Resource):
def get(self, cityName):
docs_list = list(client['mongodbhotels']['wheather_conditions'].find(
filter = {
'name': { "$eq" : cityName}
},
allow_partial_results = True )
)
json_response = json.dumps(docs_list, default=json_util.default)
return json.loads(json_response)
api.add_resource(HotelList, '/')
api.add_resource(Hotel, '/<string:cityName>')
if __name__ == '__main__':
app.run(debug=True)
我希望使用我的参数(城市名称)得到这样的 url http://127.0.0.1:5000/Madrid
这个查询是有效的,但现在它returns一个空值
你试过吗?
class Hotel(Resource):
def get(self, cityName):
docs_list = list(client['mongodbhotels']['wheather_conditions'].find(
filter = {
'name': cityName
},
allow_partial_results = True )
)
json_response = json.dumps(docs_list, default=json_util.default)
return json.loads(json_response)
api.add_resource(HotelList, '/')
api.add_resource(Hotel, '/<string:cityName>')
if __name__ == '__main__':
app.run(debug=True)```