AAbVud
AAbVud

Reputation: 37

mongoose.connect not invoking callback after connection to mongodb

I'm trying to make a connection to MongoDB using Mongoose. But it does neither throw a error nor connect to the database. Following is my code.

const express = require('express');
const app = express();
const port = process.env.PORT || 8080;
const mongoose = require('mongoose');

console.log('Hi, there!!');    

mongoose.connect('mongodb://localhost:27017/db_name', (err) => {
 console.log('Callback called');
 if(err) throw err; 
 console.log('Connected to database');
})

In the above code none of the console.log inside the callback do happen. But any place outside the mongoose.connect do work like console.log('Hi, there!!')

Versions Used

express: 4.0.0
mongoose: 3.8.40
node: 7.7.3
mongodb: 3.4.0

Upvotes: 1

Views: 407

Answers (1)

Kevin Amiranoff
Kevin Amiranoff

Reputation: 14468

Using mongoose: 3.8.40 I got this in the console :

{ Error: Cannot find module '../build/Release/bson'
    at Function.Module._resolveFilename (module.js:470:15)
    at Function.Module._load (module.js:418:25)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/kevin/nemeacreation/sites/test/stackoverflow/node_modules/bson/ext/index.js:15:10)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3) code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version
Hi, there!!

upgrading to "mongoose": "~4.4" fixed it for me. I got the answer here : https://stackoverflow.com/a/35516644/2829540

For info the latest release of mongoose is 4.10.4

Upvotes: 2

Related Questions