Pymongo/bson: Convert python.cursor.Cursor object to serializable/JSON object

后端 未结 3 1253
臣服心动
臣服心动 2021-02-05 06:14

New to MongoDb and Python (webapp2). So, I was fetching some data from a mongodb database. But I was unable to use json.dumps on the r

3条回答
  •  梦谈多话
    2021-02-05 06:23

    Simple Solution

     // Use dumps from bson.json_util:
    from bson.json_util import dumps
    
    @app.route("/")
    def home_page():
    
        booking = dumps(mongo.db.bookings.find())
        print booking
        return  booking
    

提交回复
热议问题