code: public static boolean collectionExists(MongoDatabase db, String collectionName) {
          return db.listCollections().filter(Filters.eq("name", collectionName)).first() != null;
      }
docs: Check if a collection exists.
  
  @param db
  @param collectionName
  @return