Shawn Mclean
Shawn Mclean

Reputation: 57469

Mongoose has no method `connect`

I installed mongoose on node.js using npm. When I try to connect with this code:

mongoose = require('mongoose/').Mongoose
@db = mongoose.connect("mongodb://localhost/test")

I get this error:

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
TypeError: Object function Mongoose() {
  this.connections = [];
  this.plugins = [];
  this.models = {};
  this.modelSchemas = {};
  this.options = {};
  this.createConnection(); // default connection
} has no method 'connect'
    at new ChatService (/home/lolcoder/workspace/sampleApp/src/services/dbService.js:12:26)
    at Object.<anonymous> (/home/lolcoder/workspace/sampleApp/src/app.js:40:17)
    at Object.<anonymous> (/home/lolcoder/workspace/sampleApp/src/app.js:44:4)
    at Module._compile (module.js:441:26)
    at Object..js (module.js:459:10)
    at Module.load (module.js:348:31)
    at Function._load (module.js:308:12)
    at Array.0 (module.js:479:10)
    at EventEmitter._tickCallback (node.js:192:40)

When do mongo in terminal, i get:

MongoDB shell version: 2.0.2
connecting to: test

Anyone knows why there is no connect() method in the mongoose object?

Upvotes: 2

Views: 1704

Answers (1)

freakish
freakish

Reputation: 56467

Instead of

mongoose = require('mongoose/').Mongoose;

use

mongoose = require('mongoose/');

Upvotes: 13

Related Questions