Flask Mongoengine Automatically Connected to Local Database

28 views
Skip to first unread message

Vetri Chelvan

unread,
Oct 25, 2020, 3:49:22 PM10/25/20
to MongoEngine Developers
app = Flask(__name__)

app.register_blueprint(save_sample)

app.config['MONGODB_SETTINGS'] = {
}


database = MongoEngine()
database.init_app(app)

Here I have initialized the flask app with the cluster URL but why are the values automatically stored in the local database.

My Blueprint Code

ave_sample = Blueprint('save', __name__)

@save_sample.route('/', methods=["POST"])
def save_function():
body = request.get_json()
connect(db=body['project_id'], alias=body['project_id'])
clas = function_setter(body['project_id'])
obj = clas(name=body['name'])
obj.save()
return jsonify({"message": "success"})


Here I am using the connect the object to dynamically change my database in the cluster in order to make a multitenant application. 

Please give me a solution.

Reply all
Reply to author
Forward
0 new messages