from database import db db_list = ["table1", "table2", "table3", "table4"] for item in db_list: collection = db[item] collection.create_index([("phone", 1)]) print(list(collection.index_information()))