Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong signature calling mongodb update? #106

Open
IRT-fbachmann opened this issue May 18, 2017 · 1 comment
Open

Wrong signature calling mongodb update? #106

IRT-fbachmann opened this issue May 18, 2017 · 1 comment

Comments

@IRT-fbachmann
Copy link

IRT-fbachmann commented May 18, 2017

I had a completely other problem, however, I encounterned a possible fault in the mongodb store L389:
this.events.update({'_id' : id}, updateCommand, callback);

The corresponding function in the mongodb driver L1084 expects another signature:
Collection.prototype.update = function(selector, document, options, callback) {

No clue, why everything is still working... the function from mongodb does not handle this correctly, but returns a Promise instead of calling the callback.

@IRT-fbachmann
Copy link
Author

Meanwhile, I found why everything is working. This is from the mongodb driver:

Collection.prototype.update = function(selector, document, options, callback) {
  var self = this;

// [...]

  // Execute using callback
  if(typeof callback == 'function') return updateDocuments(self, selector, document, options, callback);

  // Return a Promise
  return new this.s.promiseLibrary(function(resolve, reject) {
    updateDocuments(self, selector, document, options, function(err, r) {
      if(err) return reject(err);
      resolve(r);
    });
  });
}

The callback is not called in the first place, because we're calling it incorrectly. So, it proceeds and creates the promise. updateDocuments however, interprets options, which is our callback function, as the callback we'd expect to resolve the promise. updateDocument calls our callback from within the promise, but not the handler that ought to resolve the promise.

Eventually, we end with an unresolved promise...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant