Thursday 28 February 2019

Is is safe to use mongo.db as global variable?

I'm making a http server using nodejs. Here is a piece of the code:var mongo = new MongoClient(dbUrl);mongo.connect(function(err) {db = mongo.db('geeki')});I use db =, not let db =, so that the variable db can be used in all my functions. I have heard many advices that "don't use global variable in multiple thread nodejs". So my question is, if I use db this way, what problem maybe occur?

Submitted February 28, 2019 at 03:55PM by ypsthelove

No comments:

Post a Comment