spring-data-mongodb icon indicating copy to clipboard operation
spring-data-mongodb copied to clipboard

How to add bypassDocumentValidation property by using MongoTemplate?

Open juefeiyan opened this issue 1 year ago • 3 comments

Hi there, we have an application that uses MongoTemplate.findAndModify the method to update MongoDB, and I want to add bypassDocumentValidation to the query.

However, I noticed that the FindAndModifyCallback doesn't pass bypassDocumentValidation from the FindAndModifyOptions to the FindOneAndUpdateOptions . I'm wondering if there's any way to bypass document validation using MongoTemplate?

juefeiyan avatar Aug 29 '24 17:08 juefeiyan

We generally do not support bypassDocumentValidation because none of our interfaces accepts such a flag (for insert, update, replace, bulk). There's no way to access Mongo's …Options models from outside.

Generally speaking, we derive a lot of these options from our domain models. How are you using bypassDocumentValidation? Is that a one-time thing or something you would want to activate whenever working with such an entity?

mp911de avatar Aug 30 '24 13:08 mp911de

We want to add schema validation but don't want to impact our customers. The idea is that we set bypassschenavalidation to true, then remove it if we confirmed everything is ok. Is it possible to add bypassschenavalidation to the FindAndModifiedOption and pass it to the FindAndUpateOption? I can draft the PR if it is possible

juefeiyan avatar Aug 30 '24 15:08 juefeiyan

We generally do not support bypassDocumentValidation because none of our interfaces accepts such a flag (for insert, update, replace, bulk). There's no way to access Mongo's …Options models from outside.

Generally speaking, we derive a lot of these options from our domain models. How are you using bypassDocumentValidation? Is that a one-time thing or something you would want to activate whenever working with such an entity?

And for the question, we want to activate bypass schema validation whenever working with such an entity

juefeiyan avatar Aug 30 '24 15:08 juefeiyan