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

Support mongoose 5 #36

Closed
gforge opened this issue Jan 31, 2018 · 6 comments
Closed

Support mongoose 5 #36

gforge opened this issue Jan 31, 2018 · 6 comments

Comments

@gforge
Copy link
Contributor

gforge commented Jan 31, 2018

Just noticed that mongoose 5 was released. Here's the how-to-upgrade: https://github.com/Automattic/mongoose/blob/master/migrating_to_5.md

After a quick glance I don't think there should be any issues with upgrading :-)

@gforge
Copy link
Contributor Author

gforge commented Mar 16, 2018

Since the problem with 5.0.7 and above is a bug I figure we continue the discussion in the issue section instead of in the PR.

I've created pure test case for mongoose (planned adding it to an mongoose issue, note change mongoose.model to db.model when testing in the mongoose-package):

it('statics', async () => {
  var called = false;
  var test_plugin = function(schema) {
    schema.statics.count = function() {
      called = true;
      return mongoose.Model['count'].apply(this, arguments).where('filter').eq(true);
    }
  }

  var TestSchema = new Schema({ name: String, filter: Boolean });
  TestSchema.plugin(test_plugin);
  var TestModel = mongoose.model('PluginTests', TestSchema);

  await TestModel.create(
      [
          { name: 'Obi-Wan Kenobi', filter: true},
          { name: 'Darth Vader', filter: false},
          { name: 'Luke Skywalker', filter: true}
      ]);

  assert.equal(called, false);
  var count = await TestModel.count();
  assert.equal(called, true);
  assert.equal(count, 2);
});

Annoyingly this seems to pass without any issues.

@gforge
Copy link
Contributor Author

gforge commented Mar 16, 2018

Ok, so I have found the culprit: passing a function fails due to the kareem update in version 2.0.5: mongoosejs/kareem@5afc5b9#diff-168726dbe96b3ce427e7fedce31bb0bcR307

Thus when I use the following test case it fails:

it('statics', async (done) => {
  var called = false;
  var test_plugin = function(schema) {
    schema.statics.count = function() {
      called = true;
      return mongoose.Model['count'].apply(this, arguments).where('filtered').ne(true);
    }
  }

  var TestSchema = new Schema({ name: String, filtered: Boolean }, { collection: 'mongoose_delete_test10'});
  TestSchema.plugin(test_plugin);
  var TestModel = mongoose.model('PluginTests', TestSchema);

  await TestModel.create(
      [
          { name: 'Obi-Wan Kenobi', filtered: true},
          { name: 'Darth Vader'},
          { name: 'Luke Skywalker', filtered: true}
      ]);

  assert.equal(called, false);
  return TestModel.count((err, count) => {
    assert.equal(called, true);
    assert.equal(count, 1);
    done();
  });
});

@vkarpov15
Copy link

This issue will be fixed with mongoose 5.0.12. Thanks for reporting 👍

@nishant-lbb
Copy link

Is the support available now for mongoose 5+ ?

@vkarpov15
Copy link

@nishant-lbb should be as long as you're using mongoose@^5.0.12

@dsanel
Copy link
Owner

dsanel commented Dec 10, 2018

Fixed in v0.5.0

@dsanel dsanel closed this as completed Dec 10, 2018
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

4 participants