Hangs on an empty mongodb database #15

Closed
mdz opened this Issue Feb 5, 2012 · 4 comments

Comments

Projects
None yet
3 participants

mdz commented Feb 5, 2012

If there are no collections in the database, database-cleaner will hang, because it never calls the callback. collections.forEach will simply do nothing when collections has no items in it.

Owner

emerleite commented Feb 7, 2012

Its really a bug. I'm finishing the fix and the revision will be published in about an hour.

Owner

emerleite commented Feb 7, 2012

Fixed by #14

emerleite closed this Feb 7, 2012

Owner

emerleite commented Feb 7, 2012

Please update your versions to 0.7.0. It corrects Issues #13, #14 and #15. Thanks for the feedback

This still fails with Mongoose 2.8.2. The callback is still never called.

in mongodb/cursor.js #toArray if this.each has not values to iterate through, it will never return.

Cursor.prototype.toArray = function(callback) {
  var self = this;

  if(!callback) {
    throw new Error('callback is mandatory');
  }

  if(this.tailable) {
    callback(new Error("Tailable cursor cannot be converted to array"), null);
  } else if(this.state != Cursor.CLOSED) {
    var items = [];

    this.each(function(err, item) {
      if(err != null) return callback(err, null);

      if(item != null && Array.isArray(items)) {
        items.push(item);
      } else {
        var resultItems = items;
        items = null;
        self.items = [];
        // Returns items
        callback(err, resultItems);
      }
    });
  } else {
    callback(new Error("Cursor is closed"), null);
  }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment