docker pull mongo:latest
mkdir /home/kv/mongondata
docker run --privileged --name kv-mongo -p 27017:27017 \
-v /home/kv/mongondata:/data/db --restart=on-failure:3 \
-d mongo:latest
# --restart=on-failure:3:是指容器在未来出现异常退出(退出码非0)的情况下循环重启3次
# -v 映射容器的/data/db到本地
python新建集合并插入一条数据后,可通过Navicat连接MongoDB数据库
import pymongo
my_client = pymongo.MongoClient("mongodb://localhost:27017/")
my_db = my_client["hx"]
my_col = my_db["sites"]
my_dict = {"name": "zzw", "alexa": "10", "url": "https://https://www.baidu.com"}
mycol.insert_one(my_dict)