manan maniyar
manan maniyar

Reputation: 11

running simple mongodb on c9.io but getting error

    var MongoClient = require('mongodb').MongoClient;
    //basic mongodb code 
    // Connect to the db
    //create a new database called test
    MongoClient.connect("mongodb://localhost:27017/exampleDb", function(err, db) {
      if(err) { return console.dir(err); }

      db.collection('test', function(err, collection){
          if(err) console.log(err);
          else console.log(collection);
      });

      db.collection('test', {w:1}, function(err, collection){
          if(err) console.log(err);
          else console.log(collection);
      });

      db.createCollection('test', function(err, collection){
          if(err) console.log(err);
          else console.log(collection);
      });

      db.createCollection('test', {w:1}, function(err, collection){
          if(err) console.log(err);
          else console.log(collection);
      });

    });

The error being shown is:

node index.js
/home/ubuntu/workspace/basic_version/node_modules/mongodb/lib/mongo_client.js:799
          throw err;
          ^

TypeError: db.collection is not a function
    at /home/ubuntu/workspace/basic_version/index.js:7:6
    at args.push (/home/ubuntu/workspace/basic_version/node_modules/mongodb/lib/utils.js:405:72)
    at /home/ubuntu/workspace/basic_version/node_modules/mongodb/lib/mongo_client.js:271:5
    at connectCallback (/home/ubuntu/workspace/basic_version/node_modules/mongodb/lib/mongo_client.js:935:5)
    at /home/ubuntu/workspace/basic_version/node_modules/mongodb/lib/mongo_client.js:796:11
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
    at process._tickCallback (internal/process/next_tick.js:104:9)

Upvotes: 1

Views: 26

Answers (0)

Related Questions