0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Python3: MongoDB のデータを削除 (Delete)

Posted at

プログラム

フォルダー構造

$ tree -a
.
├── .env
├── config_mariadb.py
└── mongo_delete.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 のデータを作成 (Create)

実行結果

$ ./mongo_delete.py t1167
*** 開始 ***
t1167
*** 終了 ***
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?