How to configure mongo encrypted information in mongo-engine
This article introduces how to configure mongo encryption information in mongo-engine, the content is very detailed, interested friends can refer to, hope to be helpful to you.
Config configuration
For mongo, enter username, password, authentication_source with encryption
Multi-library configuration is distinguished by alias (if left empty, the default is default), which will be used later.
MONGODB_SETTINGS = [{"db": "openplatform_datacenter", "host": ["localhost:27017", "localhost:27018"], "username": "", "password": "", "authentication_source": "admin",}, {"db": "test", "host": ["localhost:27017", "localhost:27018"] "username": "", "password": "", "authentication_source": "admin", "alias": "test",}] Model code class OriginalDataApplyModel (db.Document): meta = {"db_alias": "test", # correlate alias to the library configuration of test} user_id = StringField (required=True) call case
Extensions.py
# coding: utf-8 from flask_mongoengine import MongoEngine db = MongoEngine () def init (app): db.init_app (app)
Test.py
# coding: utf-8 from extensions import db pymongo_default = db.get_db () # get the pymongo db instance, use the configuration pymongo_default ["test"] .insert ({"name": "test_alias"}) # of the alias for default in MONGODB_SETTINGS # insert data pymongo_test = db.get_db ("test") # into the test table of the openplatform_datacenter library Use the configuration pymongo_test ["test"] .insert ({"name": "test_alias"}) # of alias for test in MONGODB_SETTINGS to insert data into the test table of the test library. Create (user_id= "123") # insert data into the box_model table of the test library using orm
Note that mongo encryption only works for a certain db, so when you use db.get_db (), you add mongo authentication (execute MongClient.auth), and then get the library instance.
This is the end of the information on how to configure mongo encryption in mongo-engine. I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can share it for more people to see.