Thursday, January 17, 2019

MongoDB: Find Query



Code

==============================
from flask import Flask
from flask import jsonify
from flask_pymongo import PyMongo

app = Flask(__name__)

app.config['MONGO_DBNAME'] = 'esawal'
app.config['MONGO_URI'] = 'mongodb://localhost:27017/esawal'

mongo = PyMongo(app)

@app.route('/', methods=['GET'])
def get_all_stars():
  star = mongo.db["customers"]

  output = []
  for s in star.find():
    output.append({'address' : s['address'], 'name' : s['name']})


  return jsonify({'result' : output})


if __name__ == '__main__':
    app.run(debug=True)
==============================

RESPONSE

==============================

==============================


MONGO DB Command line Output

======================================


=======================================

No comments:

Post a Comment