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.

プログラム

mongo_update.py
#! /usr/bin/python
#
#	mongo_update.py
#
#					Jun/26/2024
#
import	sys
import	pymongo
import	datetime
#
# -------------------------------------------------------------------
def	mongo_update_proc (db_aa,collection,key_in,population_in):
	date_mod = datetime.datetime.now ()
	db_aa[collection].update_one({"key": key_in},{"$set":{"population": population_in,"date_mod": '%s' % date_mod}})
#
# -------------------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")
#
key_in = sys.argv[1]
population_in = int(sys.argv[2])
sys.stderr.write("%s\t%d\n" % (key_in, population_in))
#
collection='saitama'
data_base='city'
#
client = pymongo.MongoClient('mongodb://localhost:27017/')
db = client[data_base]
#
mongo_update_proc(db,collection,key_in,population_in)
#
sys.stderr.write("*** 終了 ***\n")
# -------------------------------------------------------------------

実行結果

$ ./mongo_update.py t1163 459268700
*** 開始 ***
t1163	459268700
*** 終了 ***
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?