Giter VIP home page Giter VIP logo

Comments (6)

matthewmueller avatar matthewmueller commented on August 23, 2024

+1, trying to get some kind of feedback that the connection hasn't been established.

from monk.

rauchg avatar rauchg commented on August 23, 2024

Yep basically we need to re-emit as error. Also, if an error occurs before open was emitted, we can fire it as connection_error as well.

from monk.

rauchg avatar rauchg commented on August 23, 2024

I also wonder whether we have open and close haha

from monk.

matthewmueller avatar matthewmueller commented on August 23, 2024

haha, i was actually getting open events even when i didn't have mongod running. That seemed a bit off, but I wasn't sure.

Here's what i had:

monk = require('monk')(url);

monk.on('open', function() {
  // prob shouldn't be firing when mongod not running...
});

from monk.

carloscarcamo avatar carloscarcamo commented on August 23, 2024

+1

from monk.

carloscarcamo avatar carloscarcamo commented on August 23, 2024

Maybe the bug is on manager.js in:

 this.driver.open(this.onOpen.bind(this));

What if we just pass a callback and emit events?, something like:

var _this = this;
this.driver.open(function (error) {
  if (error) {
    _this.emit('error', error);
  } else {
    _this.emit('open')
  }
});

...

if (fn) {
  this.once('open', fn);
  this.once('error', fn);
}

Then we can pass a callback to check for errors, something like:

var db = monk(uri, function(err) {
  if (err) console.error(err);
});

or

var db = monk(uri, opts, function(err) {
  if (err) console.error(err);
});

or

var db = monk(uri);
db.on('error', function (err) { console.error(err); })
db.on('open', function () { console.log('open'); });

Mongoskin will return an error if the connection fails:

[ERROR] [Error: failed to connect to [127.0.0.1:27017]]

from monk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.