title: .net core + MongoDB how to create database dynamically
body: <p>I have a .net core project with MongoDB.</p>
  
  <p>Before starting to work with this I need to create DB for this manually.</p>
  
  <p>I mean I need to go mongo shell and use next commands like this:</p>
  
  <pre><code>use admin
  db.createUser(
    {
      user: "admin",
      pwd: "abc123!",
      roles: [ { role: "root", db: "admin" } ]
    }
  );
  exit;
  </code></pre>
  
  <p>But I don't like do this every time when I need to deploy my project.</p>
  
  <p>How can I automate this process and creating DB dynamically from C# code or use some other solution if it's possible?</p>
  
  <p>P.S. I use <a href="https://www.codeproject.com/Articles/1151842/Using-MongoDB-NET-Driver-with-NET-Core-WebAPI" rel="nofollow noreferrer">this article</a> for building work with MongoDB + .net core.</p>