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

docs(middleware): list validate as a potential query middleware #13057

Merged
merged 1 commit into from Feb 21, 2023

Conversation

vkarpov15
Copy link
Collaborator

Re: #12680

Summary

#12680 pointed out that we don't list 'validate' as a potential query middleware. This fixes the docs. Below is an example of using query middleware for validate()

'use strict';

const mongoose = require('mongoose');

const schema = new mongoose.Schema({ name: String });

schema.pre('validate', () => {
  console.log('Regular pre validate');
});
schema.pre('validate', { query: true, document: false }, () => {
  console.log('Pre query validate');
});

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

run().catch(err => console.log(err));

async function run() {
  await mongoose.connect('mongodb://localhost:27017/test');

  const doc = new Test();
  await doc.validate();

  console.log('----');
  await Test.updateOne({}, { name: 'bar' }).setOptions({ runValidators: true });
}

Examples

@hasezoey hasezoey added the docs This issue is due to a mistake or omission in the mongoosejs.com documentation label Feb 21, 2023
@vkarpov15 vkarpov15 merged commit 768f203 into master Feb 21, 2023
@vkarpov15 vkarpov15 added this to the 6.9.3 milestone Feb 21, 2023
@hasezoey hasezoey deleted the vkarpov15/validate-middleware-docs branch February 21, 2023 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This issue is due to a mistake or omission in the mongoosejs.com documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants