title: Create a MongoDB user from commandline
body: <p>I have set up a MongoDB database with an <code>admin</code> user that has only administrative rights, not read or write access to databases.</p>
  
  <p>What I now would want to do is:</p>
  
  <ul>
  <li>Add a new database,</li>
  <li>and add a new user to that database.</li>
  </ul>
  
  <p>And: I need to do this from the command line. So I tried:</p>
  
  <pre><code>$ mongo admin -u admin -p admin --eval "db.addUser('dummyuser', 'dummysecret')"
  </code></pre>
  
  <p>(Please note that as I am still running MongoDB 2.0, I am using the old format of <code>db.addUser</code>.)</p>
  
  <p>This would make perfect sense if I could also tell it which database this user should be for. But now I am struggling. How do I specify the database for this command? If I were in the interactive shell, I could just run</p>
  
  <pre><code>&gt; use dummydb
  </code></pre>
  
  <p>but how do I do this from the command line? My first try was to concatenate both commands with a <code>;</code>, but this didn't work:</p>
  
  <pre><code>$ mongo admin -u admin -p admin --eval "use dummydb;db.addUser('dummyuser', 'dummysecret')"
  </code></pre>
  
  <p>just gives me syntax error.</p>
  
  <p>How do I get this right?</p>