安装
$ python3 -m pip3 install pymongo
创建数据库、集合、字典记录
if __name__ == "__main__":
mongo_str = "mongodb://localhost:27017/"
client = pymongo.MongoClient(mongo_str)
db = client["db_1"]
col_1 = db["col_1"]
dict_1 = {"name": "zhangsan", "age": 18}
x = col_1.insert_one(dict_1)
print(x)
print(x.inserted_id)