Performing document validation from a driver, and db.collection.validate() return issues

I have two questions about performing document validation:

  1. Can you perform the equivalent of mongosh db.collection.validate() from a driver (I happen to be using the latest Go driver)? The Go driver provides Database.RunCommand(…) but I don’t see how to run an administrative command on an individual collection. I’m probably missing something obvious.

  2. When a collection contains invalid documents, what is the expected output when running db.collection.validate(), specifically values for nInvalidDocuments, warnings, or errors? If I have a collection with invalid documents (validationLevel: strict, validationAction: warn) and I run db.collection.validate(), the response does not indicate any errors at all: nInvalidDocuments is 0, and warnings and errors are empty. Yet, I know validation was performed because the server logs indicate the result of the validation command had invalid docs. Does this sound like a bug or are my expectations incorrect?

Thanks!

Elliot

I should add that I am using Mongo DB 5.0.3

  1. Can you perform the equivalent of mongosh db.collection.validate() from a driver (I happen to be using the latest Go driver)? The Go driver provides Database.RunCommand(…) but I don’t see how to run an administrative command on an individual collection. I’m probably missing something obvious.

The answer to this is: db.RunCommand(ctx, bson.D{{"validate", "collectionName"}}), where db is a var *mongo.Database.

Still looking for an answer to question 2, above. It does seem like the response from Mongo is incorrect (not a mongosh or driver issue), as nInvalidDocuments, warnings[], and errors[] are incorrect in the driver response as well as mongosh.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.