title: How can I execute db.copyDatabase through NodeJS's MongoDB native driver?
body: <p>I do have a shell script that invokes </p>
  
  <pre><code>mongo --eval "db.copyDatabase('somedatabase', 'somedatabase_duplicate', 'sourcehost')"
  </code></pre>
  
  <p>to copy a database.</p>
  
  <p>Currently I am stuck with doing the same from within a Node.JS application. Calling </p>
  
  <pre><code>mongoCommand = `db.copyDatabase("somedatabase", "somedatabase_duplicate", "localhost")`;
  db.command(mongoCommand, function(commandErr, data) {
        if(!commandErr) {
          log.info(data);
        } else {
          log.error(commandErr.errmsg);
        }
      });
  </code></pre>
  
  <p>Always resulsts in a "no such command" error message.</p>
  
  <p>Edit for clarification: Using db.admin().command() results in the same problem and using the command suggested in <a href="https://stackoverflow.com/questions/16576541">enter link description here</a>, too.</p>
  
  <p>What's the correct way to call this command or, alternatively, to clone a database from Node.JS? </p>