Mongodb not returning promise (using package version 2.1.18 )

26 views
Skip to first unread message

Maisnam Raju

unread,
May 10, 2016, 11:48:53 PM5/10/16
to node-mongodb-native
I am trying to use promises to return the database connection in nodejs but the promise is returned in an asynchronous manner. 
"use strict";

var MongoClient = require('mongodb').MongoClient;
var Joi  = require('joi');
var co   = require('co');
var url  = 'mongodb://localhost:27017/blue_water';
var CrewModel = require('./crew');

var DB;

MongoClient.connect(url).then(function(db) {
    console.log(db);
});


console.log(2);


The console.log() is returned before the promise function is executed. Am I missing something here ? 
Reply all
Reply to author
Forward
0 new messages