我正在尝试编写一个简单的Web服务,它有一个端点/allTests
。端点返回mongo集合中的所有文档。我正在尝试使用Flask-Pymongo库执行此操作。但它返回一个空的结果列表,即使特定的mongo集合中有一些文档。任何人都可以确定我做错了吗?
import json
from flask import Flask
from flask.ext.pymongo import PyMongo
from pymongo import MongoClient
from mabstats import config
app = Flask(__name__)
app=config.get_config(app) #adds the MONGO_URI to app.config
mongo = PyMongo(app)
@app.route('/health')
def healthcheck():
return json.dumps({'value':'Healthy!'})
@app.route('/allTests')
def gettests():
collection_name=app.config['MONGO_ARCHIVE_COLLECTION'] #name of collection
print "Collection",collection_name
collection=getattr(mongo.db,collection_name)
print "Collection Object",collection
results=[item for item in collection.find()]
return json.dumps(results)
if __name__ == "__main__":
app.run(debug=True)