mongo-rust-driver icon indicating copy to clipboard operation
mongo-rust-driver copied to clipboard

Modify a Validator

Open GreeFine opened this issue 1 year ago • 2 comments

To have a validator set in a collection, I use the validator field in the CreateCollectionOptions.

But I need to be able to change the validation schema of an existing collection, and I found no way of doing it. (without dropping and recreating the Collection)

Is there a function/option I didn't find, or is the feature missing ? If missing, could I propose the feature in a PR, and expect it's to be merged at some time ?

GreeFine avatar Mar 27 '24 14:03 GreeFine

You're right that the Rust driver doesn't expose a helper method for that; as far as I can tell, drivers for other languages don't either. It's not part of the MongoDB driver specification, as we generally think of it as an administrative action rather than a client application operation.

That said, you're not the first to ask for this, so I'm going to re-open internal discussion on this :) While I appreciate the offer of a PR, I don't think we'd be able to accept one for new user-facing API surface. In the meanwhile, you can use the run_command method to directly run the collMod operation (example).

abr-egn avatar Apr 01 '24 17:04 abr-egn

Thanks for the example that might work.

I am very surprised by the fact that this isn't something that you already had on the other drivers, makes sense that a new user-facing API needs to be done by your team.

Is there a link to the internal discussion or any resources on this issue ? I am curious as to why it is the case, and also looking for how we should best use the validators. In our project, we use them to prevent, detect mismatch data exchanged between two crates through the Mongo database, but the data format, schema and thus validator are evolving rapidly, and we want to automatically have the newest validators in place. (a bit like embedded migration for PostgreSQL)

GreeFine avatar Apr 03 '24 07:04 GreeFine