title: How to create a database in Mongo using Python?
body: <p>I have written the below Python program to create a MongoDB.</p>
  
  <pre><code>import pymongo
  
  myclient = pymongo.MongoClient('mongodb://localhost:27017/')
  
  mydb = myclient['mydatabase']
  
  dblist = myclient.list_database_names()
  
  if "mydatabase" in dblist:
    print("The database exists.")
  else :
    print("The database does not exists.")
  </code></pre>
  
  <p>But while I execute the program , I get the result as </p>
  
  <p><em>The database does not exists.</em></p>
  
  <p>Why so? Is there something that I am missing ?</p>
  
  <p>I am following the code mentioned in <a href="https://www.w3schools.com/python/python_mongodb_create_db.asp" rel="nofollow noreferrer">W3Schools Tutorial</a></p>