log4js-node-mongodb icon indicating copy to clipboard operation
log4js-node-mongodb copied to clipboard

Handle undefined db on connect

Open nearwood opened this issue 9 years ago • 3 comments

Added an if statement to check if db is defined before attempting to use it in the connect method. Also added an option for skipping errors on insert in included commits but removed them. Removed connection string config from error message, to rely just on MongoDB error object for debugging (relevant to my project).

So, basically, just added the db check to the connect method. Feel free to skip the other stuff, I was just prototyping some stuff for a project.

nearwood avatar Aug 30 '16 19:08 nearwood

Thanks for the pull request. I guess I will merge the db check. Just out of curiosity. What is your scenario that MongoClient.connect() callback is called with no error, but the db object is null or undefined. Sounds like a weird combination.

4kochi avatar Aug 30 '16 21:08 4kochi

There was an error, but the connect() method continues to try and use the db object that may not be defined. So, you could also return in the if (err) conditional block for the same effect.

Sorry for the delayed response, I'm not getting notifications anymore :(

nearwood avatar Oct 03 '16 14:10 nearwood

Ok, no problem. Thanks for the clarification. I will merge the pr after my vacation.

4kochi avatar Oct 03 '16 15:10 4kochi