检查集合是否存在

  1. import pymongo
  2.  
  3. myclient = pymongo.MongoClient('mongodb://localhost:27017/')
  4.  
  5. mydb = myclient['mydatabase']
  6.  
  7. mycol = mydb["customers"]
  8.  
  9. print(mydb.list_collection_names())