Add a validator to a Mongodb collection with pymongo
问题 I am trying to add a validator to a MongoDB collection using pymongo. The command I would like to run adapted from here Is equivalent to this: db.runCommand( { collMod: "contacts", validator: { phone: { $type: 'string' } }, validationLevel: "moderate" } ) { "ok" : 1 } And subsequently will throw an error if a non-string datatype is inserted tin the phone field Using python I did the following: db.command({'collMod': 'contacts', 'validator': {'phone': {'$type': 'string'}}, 'validationLevel':