title: Node Mongo db.runCommand is not a function
body: <p>I am following this <a href="https://stackoverflow.com/questions/18455217/mongodb-and-mongojs-cant-get-runcommand-to-work-for-text-queries?utm_medium=organic&amp;utm_source=google_rich_qa&amp;utm_campaign=google_rich_qa">SO question</a> to run a command on Mongo using Node, the command I want to run is:</p>
  
  <pre><code>db.runCommand( { serverStatus: 1, repl: 0, metrics: 0, locks: 0, wiredTiger: 
  0, logicalSessionRecordCache: 0, transactions: 0, logicalSessionRecordCache: 
  0, tcmalloc: 0, storageEngine: 0, opLatencies: 0, opcountersRepl: 0, 
  network: 0, extra_info: 0, asserts: 0, globalLock: 0 } )
  </code></pre>
  
  <p>But when I try something like:</p>
  
  <pre><code>db.runCommand( { serverStatus: 1 }, function(err, data) {
      if (!err)  console.log(data);
  });
  </code></pre>
  
  <p>or</p>
  
  <pre><code>db.command( { serverStatus: 1 }, function(err, data) {
      if (!err)  console.log(data);
  });
  </code></pre>
  
  <p>or even the one in the question</p>
  
  <pre><code>db.command({ distinct: "Messages", key: "session" }, function (err, data) 
  {
      if (!err)  console.log(data);
  });
  </code></pre>
  
  <p>I get a <code>is not a function</code> error:</p>
  
  <p><code>TypeError: db.runCommand is not a function</code>
  <code>TypeError: db.command is not a function</code></p>
  
  <p>Here's my code:</p>
  
  <pre><code>import { MongoClient, Db, ObjectId } from 'mongodb';
  ...
  async pingServer() {
      let connectionStr = 'mongodb://localhost:27017';
      MongoClient.connect(connectionStr, function (err, db) {
          if(!err) {
              db.command({ distinct: "Messages", key: "session" }, function (err, data) {
                  if (!err)  console.log(data);
              });
          } else {
              console.log("error",err);
          }
      })
  }
  </code></pre>
  
  <p>I am using mongodb 3.0.6</p>
  
  <p>I also tried doing <code>var MongoClient = require("mongodb").MongoClient;</code> instead of the import (I am working with TypeScript) and got the same result.</p>
  
  <p>What am I doing wrong?</p>