Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure mongo encrypted information in mongo-engine

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report