title: Getting keys/columns of collection in mongodb - nodejs
body: <p>I am trying to get all the columns/keys of an collection using the following code:</p>
  
  <pre><code>var Db          = require('mongodb').Db; //for mongodb
  var Connection  = require('mongodb').Connection;
  var Server      = require('mongodb').Server;
  var BSON        = require('mongodb').Server;
  var ObjectID    = require('mongodb').ObjectID;
  
  
  DbModels = function(host, port){
    this.db = new Db('test', new Server(host, port,{auto_reconnect:true},{}));
    this.db.open(function(){});
  };
  
  DbModels.prototype.testDb=function(_collection){
      console.log("Collection:");
      console.log(this.db.collection('persons').find());
      var mr = this.db.runCommand({
        "mapreduce":"br_205_results",
        "map" : function(){
            for (var key in this){emit(key, null);}
          },
        "reduce" : function(key, stuff){
            return null;
          }
        });
        console.log(mr);
      db[mr.result].distinct("_id");
  
  };
  </code></pre>
  
  <p>But I get the following error:</p>
  
  <pre><code>TypeError: Object [object Object] has no method 'runCommand'
      at [object Object].testDb (c:\Program Files\nodejs\DbModels.js:17:22)
      at c:\Program Files\nodejs\socketio.js:164:14
      at callbacks (c:\Program Files\nodejs\node_modules\express\lib\router\index.js:272:11)
      at param (c:\Program Files\nodejs\node_modules\express\lib\router\index.js:246:11)
      at pass (c:\Program Files\nodejs\node_modules\express\lib\router\index.js:253:5)
      at Router._dispatch (c:\Program Files\nodejs\node_modules\express\lib\router\index.js:280:4)
      at Object.handle (c:\Program Files\nodejs\node_modules\express\lib\router\index.js:45:10)
      at next (c:\Program Files\nodejs\node_modules\connect\lib\http.js:203:15)
      at Object.handle (c:\Program Files\nodejs\node_modules\now\lib\now.js:213:7)
      at next (c:\Program Files\nodejs\node_modules\connect\lib\http.js:203:15)
  </code></pre>
  
  <p>Any idea, how I can solve this?</p>