1 安装pymongo

pip install pymongo

2 连接数据库

  1. import pymongo
  2. def mongo_init1():
  3. db = pymongo.MongoClient(host='0.0.0.0', port=27017, tz_aware=True)
  4. def mongo_init2():
  5. db = pymongo.MongoClient('mongodb://0.0.0.0:27017', tz_aware=True)