javascript - Connecting to mongo database through constructor -


i have mongo database connect when create instance of mongo manager class. constructor calling connect routine , trying set db should returned mongo source. not getting returned when call mongodb.mongoclient.connect , callback function isn't trigger @ all

class mongomanager {             constructor(url) {                 this.url = url;                 this.db = {};                 this.connect(this.url);             }              connect(url) {                 mongodb.mongoclient.connect(this.url, {                     connecttimeoutms: 15000                 }, (err, db) => {                     console.log("hello");                     if (err) {                         throw err;                     }                     this.db = db;                 });                 this.db = db;             }     } } 

since i'm not getting callback mongodb.mongoclient.connect() not able set db @ constructor level

p:s:- url mongo client above coming fine when console log i.e., mongodb://localhost:27017/dts

from above statement console.log("hello") never gets triggerred


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -