# 查看是否有以“id”創建的倒序索引,如果沒有則添加
indexs = collection_target.index_information()
if "id_-1" not in indexs:
collection_target.create_index([("id", -1)])
# 先查詢表中已經存在的記錄的最大id的記錄
find_one = collection_target.find().sort([('id', pymongo.DESCENDING)]).limit(1)
max_id = None
for row_data in find_one:
max_id = row_data["id"]