I know many variants of this question have been asked already, but none are really specific to the problem I'm facing.
I'm using MongoDB with a python backend and RESTful API, and I have such code:
cluster = pymongo.Mongoclient("secret_information")
db = cluster['test']
userCollection = db['users']
@app.route('/api/getUsers', methods=['GET'])
def getUsers():
allUsers_cursor = userCollection.find({})
allUsers = list(allUsers_cursor)
#the below line gives me "ObjectId is not JSON serializable error" message:
return jsonify(allUsers), 200
My database is very simple and looks something like this:
[{
title: "personA",
description: "a person"
},
{
title: "personB",
description: "another person"
}]
There must be an easy way to deal with the ObjectId problem - I can't imagine that something as ubiquitous to the database as ObjectId would cause such big problems for all users. Help appreciated!