Friday, January 18, 2019

MongoDB: Collections name in db

Def

CODE
================================
from flask import Flask
from flask import jsonify
from flask import request
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.collection_names()

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

  return jsonify({'result' : star})


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

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


RESULT
================================
{
  "result": [
    "insert", 
    "esawal", 
    "customers", 
    "flightData"
  ]
}
================================

No comments:

Post a Comment