[Vuejs]-Mongoose.connect is not a function after exports from other files

0👍

You’re using a .then(...).catch(...) function with mongoose which it doesn’t support by default. The safe way to use Promises with mongoose is by passing a global Promise.

const mongoose = require('mongoose');
const url = 'mongodb://localhost:27017/dev6'

mongoose.Promise = global.Promise;

connect = () =>{
    mongoose.connect(url, { useNewUrlParser: true }).then(console.log('Database Connected')).catch(err => {console.log(err)});
}
...
...

I hope this helps you.

0👍

I had a similar problem. Was using

let mongoose = require("mongoose");

As soon as I switched to

const mongoose = require("mongoose");

problem solved.

Leave a comment