I am trying to validate an inserted document against a schema, and was trying to find a way to validate the inserted document.
There are libraries like MongoEngine
that say they do the work, but is there a way to do document validation directly via pymongo
?
MongoDB supports document validation at the engine level so you'll pick it up via pymongo. You declare your "schema" (rules actually) to the engine. Here's a great place to start: https://docs.mongodb.com/manual/core/document-validation/
The python driver docs are indeed a little light on how to use the
db.command
. Here is a complete working example: