Deprecated mongoose method

0

I'm trying to make a connection with mblab but the connection method is deprecated. Version of the method is 4.9.7. What I need is 4.13.7.

Structure:

server.js

const express = require('express');
const morgan = require('morgan');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const hbs = require('hbs');
const expressHbs = require('express-handlebars');
const config = require('./config/secret');

const app = express();

mongoose.connect(config.database, function(err) {
  if (err) console.log(err);
  console.log("connected to the database");
});

app.engine('.hbs', expressHbs({ defaultLayout: 'layout', extname: '.hbs' }));
app.set('view engine', 'hbs');
app.use(express.static(__dirname + '/public'));
app.use(morgan('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

const mainRoutes = require('./routes/main');

app.use(mainRoutes);


app.listen(3030, (err) => {
  if (err) console.log(err);
  console.log('Running on port ${3030}');
});

secret.js

module.exports = {
  database: ''

}

main.js

const router = require('express').Router();
const User = require('../models/user');

router.get('/', (req, res, next) => {
  res.render('main/landing');

});

router.get('/create-new-user', (req, res, next) => {
  var user = new User();
  user.email = "[email protected]"
  user.name = "Jack";
  user.password = "123456";
  user.save(function(err) {
    if (err) return next(err);
    res.json("Successfully created");
  });
});


module.exports = router;

user.js

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const UserSchema = new Schema({
  email: { type: String, unique: true, lowercase: true },
  name: String,
  password: String,
  photo: String,
  tweets: [{
    tweet: { type: Schema.Types.ObjectId, ref: 'Tweet' }
  }]
});

module.exports = mongoose.model('User', UserSchema);
dependencias": {
    “body-parser”: “^1.18.2”,
    “express”: “^4.16.2”,
    “express-handlebars”: “^3.0.0”,
    “hbs”: “^4.0.1”,
    “mongoose”: “^4.13.7”,
    “morgan”: “^1.9.0”
}
    
asked by anonymous 26.12.2017 / 04:59

1 answer

0

As quoted by the author by comment, he was getting the following error:

  

DeprecationWarning: open () is deprecated in mongoose> = 4.11.0, use openUri () instead, or set the useMongoClient option if using connect () or createConnection (). Db.prototype.authenticate method will no longer be available in the next major release 3.x as MongoDB 3.6 will only allow auth against users in the admin db and will no longer allow multiple crede ntials on a socket. Please authenticate using MongoClient.connect with auth credentials.

The error message informs that you must use the openUri() method or you are using the connect() or createConnection() method to set the useMongoClient option to true . >

mongoose.connect('mongodb://localhost/bd', { useMongoClient: true })
    
26.12.2017 / 12:06