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

Query#updateOne() error handling middleware called twice #7418

Closed
vkarpov15 opened this issue Jan 14, 2019 · 0 comments
Closed

Query#updateOne() error handling middleware called twice #7418

vkarpov15 opened this issue Jan 14, 2019 · 0 comments
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@vkarpov15
Copy link
Collaborator

const assert = require('assert');
const mongoose = require('mongoose');
mongoose.set('debug', true);

const GITHUB_ISSUE = `X`;
const connectionString = `mongodb://localhost:27017/${ GITHUB_ISSUE }`;
const { Schema } = mongoose;

run().then(() => console.log('done')).catch(error => console.error(error.stack));

async function run() {
  await mongoose.connect(connectionString);
  await mongoose.connection.dropDatabase();

  const schema = new Schema({ test: Number });
  // RegExp syntax new in Mongoose 5.3
  schema.post(/.*/, function(error, res, next) {
    console.log('Error middleware:', error.message);
    next();
  });

  const Test = mongoose.model('Test', schema);

  await Test.updateOne({}, { test: 'bar' });
}
@vkarpov15 vkarpov15 added the confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. label Jan 14, 2019
@vkarpov15 vkarpov15 added this to the 5.4.5 milestone Jan 14, 2019
vkarpov15 added a commit that referenced this issue Jan 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

No branches or pull requests

1 participant