Python3: 删除 MongoDB 数据

程序

文件夹结构

$ tree -a
.
├── .env
├── config_mariadb.py
└── mongo_delete.py
#! /usr/bin/python
#
#	mongo_delete.py
#
#					Mar/01/2023
#
import	sys
import	string
import	pymongo
#
from config_mariadb import config_mariadb_proc
# -------------------------------------------------------------------
def	mongo_delete_proc (db_aa,collection,key_in):
	db_aa[collection].delete_one ({"key": key_in})
#
# -------------------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")
#
key_in = sys.argv[1]
sys.stderr.write("%s\n" % key_in)
#
host,user,password,data_base = config_mariadb_proc()
collection='saitama'
client = pymongo.MongoClient(host,username=user,password=password,
			authSource=data_base,authMechanism='SCRAM-SHA-256')
db = client[data_base]
#
mongo_delete_proc(db,collection,key_in)
#
sys.stderr.write("*** 終了 ***\n")
#
# -------------------------------------------------------------------

.env
config_mariadb.py
请点击这里
Python3:创建 MongoDB 数据

执行结果

$ ./mongo_delete.py t1167
*** 開始 ***
t1167
*** 終了 ***
广告
将在 10 秒后关闭
bannerAds