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

bulkWrite runs validators but there is no way to turn them off with a setting #11663

Closed
eliw00d opened this issue Apr 13, 2022 · 1 comment
Closed
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@eliw00d
Copy link

eliw00d commented Apr 13, 2022

Do you want to request a feature or report a bug?

A feature.

What is the current behavior?

When using bulkWrite, I get validation errors for required fields but I am unable to set runValidators to false.

If the current behavior is a bug, please provide the steps to reproduce.

const mongoose = require('mongoose')
const { Schema } = mongoose

const testSchema = new Schema({
  name: {
    type: String,
    required: true,
  },
})

const Test = mongoose.model('Test', testSchema)

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

  await Test.create({
    name: 'Test',
  })

  await Test.bulkWrite([
    {
      replaceOne: {
        filter: { name: 'Test' },
        replacement: {},
        runValidators: false,
      },
    },
  ])

  console.log(await Test.find()) // ValidationError: Test validation failed: name: Path `name` is required.
}

run()

What is the expected behavior?

When using bulkWrite, I do not get validation errors for required fields because I set runValidators to false.

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.

Node.js: 16.13.0
Mongoose: 6.1.5
MongoDB: 4.4.12

@IslandRhythms IslandRhythms added the new feature This change adds new functionality, like a new method or class label Apr 14, 2022
@vkarpov15 vkarpov15 removed the new feature This change adds new functionality, like a new method or class label Apr 14, 2022
@vkarpov15 vkarpov15 added this to the 6.2.15 milestone Apr 14, 2022
@IslandRhythms IslandRhythms added the confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. label Apr 15, 2022
@vkarpov15
Copy link
Collaborator

vkarpov15 commented May 7, 2022

We added a skipValidation option to work around this:

  await Test.bulkWrite([
    {
      replaceOne: {
        filter: { name: 'Test' },
        replacement: {},
        skipValidation: false,
      },
    },
  ])

@vkarpov15 vkarpov15 modified the milestones: 6.3.4, 6.3.3 May 7, 2022
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

3 participants