I am still learning here and am currently trying to use FLASK to create to Restful interface
What I want to do is to pull out a collection of records from a mongo database. I have find_one() working fine and am now exploring how to itterate over a cursor
This code only displays a single record when I know there are at least 5
@app.route('/oer/api/v1.0/getType/', methods = ['GET'])
def getType():
# Prepare a dictionary object to hold the result of any processing
result = {}
# Get hold of DB connection
db_connection = getDbConnection()
db = db_connection['OER']
# Extract all records passed for the paramater that matches "Type": ie MOOC
oerType = request.args.get("oerType");
# test to see that there is something in the string if so try to get a record
# Not doing this test yet lets get it working with a known record first
for d in db.oer_records.find({"Type":oerType}):
result.update(make_public_page(d))
return jsonify(result)
So it works but only returns a single json document not a collection? I thought the result.update would append a new record each time through FYI make_public_page() removes BISON ID's to allow jsonify to work.
This is what it returns
{
"Account No": 1,
"Country/ continent": "Argentina",
"Educational Level": "Schools",
"Educational Level (ISCED)": "2|3",
"End year": "",
"Funders": "",
"Geolocation": "",
"Initiative HQ address": "",
"Initiative HQ city": "",
"Initiative URL": "http://www.gleducar.org.ar",
"Type": "OER"
}
Any help appreciated.
Thanks