fix(upload): DuplicateKey 使用 更新,避免替换触发 _id 不可变错误 (code 66)
This commit is contained in:
4
app.py
4
app.py
@@ -853,12 +853,12 @@ def upload_file():
|
||||
db_entry['enabled'] = True
|
||||
pprint.pprint(db_entry)
|
||||
|
||||
# mongoDBにデータをぶち込む(重複IDは上書き)
|
||||
# mongoDBにデータをぶち込む(重複IDは部分更新で上書きし、_id を不変に保つ)
|
||||
coll = client['taiko']["songs"]
|
||||
try:
|
||||
coll.insert_one(db_entry)
|
||||
except DuplicateKeyError:
|
||||
coll.replace_one({"id": db_entry["id"]}, db_entry, upsert=True)
|
||||
coll.update_one({"id": db_entry["id"]}, {"$set": db_entry}, upsert=True)
|
||||
# キャッシュ削除(/api/songs)
|
||||
try:
|
||||
app.cache.delete_memoized(route_api_songs)
|
||||
|
||||
Reference in New Issue
Block a user