Mongoose error: `open()` is deprecated in mongoose >= 4.11.0,

Viewed 2759

I am on cloud 9 doing colts web developer course trying to run this code:

var mongoose = require('mongoose');
mongoose.connect("mongodb://localhost/cat_app");


var catSchema = new mongoose.Schema({
    name: String,
    age: Number,
    temperament: String
});

var Cat = mongoose.model('Cat', catSchema);
//add a new cat to db
var george = new Cat({
    name: 'George',
    age: 11,
    temperament: 'Grouchy'
});

george.save(function(err, cat) {
    if(err) {
        console.log('Something went wrong!');
    }else {
        console.log('We just saved a cat to the DB: ');
        console.log(cat);
    }
});
//get all cats from DB and log each one

And I keep getting this err:

`open()` is deprecated in mongoose >= 4.11.0, use `openUri()` instead, or set the `useMongoClient` option if using `connect()` or `createConnection()`. See http:    //mongoosejs.com/docs/connections.html#use-mongo-client
Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http: //mongoosejs.com/docs/promises.html

events.js:141
      throw er; // Unhandled 'error' event
      ^
MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]
    at null.<anonymous> (/home/ubuntu/workspace/database/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:328:35)
    at emitOne (events.js:77:13)
    at emit (events.js:169:7)
    at null.<anonymous> (/home/ubuntu/workspace/database/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/connection/pool.js:280:12)
    at g (events.js:260:16)
    at emitTwo (events.js:87:13)
    at emit (events.js:172:7)
    at Socket.<anonymous> (/home/ubuntu/workspace/database/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:177:49)
    at Socket.g (events.js:260:16)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at emitErrorNT (net.js:1269:8)
    at nextTickCallbackWith2Args (node.js:458:9)
    at process._tickCallback (node.js:372:17)

I tried using mongoose 4.10.8 but then I get this err:

Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/promises.html

events.js:141
      throw er; // Unhandled 'error' event
      ^
MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]
    at null.<anonymous> (/home/ubuntu/workspace/database/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:328:35)
    at emitOne (events.js:77:13)
    at emit (events.js:169:7)
    at null.<anonymous> (/home/ubuntu/workspace/database/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/connection/pool.js:280:12)
    at g (events.js:260:16)
    at emitTwo (events.js:87:13)
    at emit (events.js:172:7)
    at Socket.<anonymous> (/home/ubuntu/workspace/database/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:177:49)
    at Socket.g (events.js:260:16)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at emitErrorNT (net.js:1269:8)
    at nextTickCallbackWith2Args (node.js:458:9)
    at process._tickCallback (node.js:372:17)

Can you help please? Thanks Guys!!!

2 Answers

I had success with npm remove mongoose then npm install mongoose@4.10.8 --save

Related