How do I connect to the mongo database with nodejs? I already consulted several sites but I can not do it correctly! Thanks for helping!
How do I connect to the mongo database with nodejs? I already consulted several sites but I can not do it correctly! Thanks for helping!
Use mongoose .
Here's an example of how to open the connection
var mongoose = require('mongoose');
global.db = mongoose.connect('mongodb://localhost:27017/neventos');
mongoose.connection.on('connected', function () {
console.log('=====Conexão estabelecida com sucesso=====');
});
mongoose.connection.on('error', function (err) {
console.log('=====Ocorreu um erro: ' + err);
});
mongoose.connection.on('disconnected', function () {
console.log('=====Conexão finalizada=====');
});
In this link has a complete project that used mongoose to make the connection .