@@ -921,12 +921,15 @@ def drop_collection(self, name_or_collection, session=None):
921921 session = session )
922922
923923 def validate_collection (self , name_or_collection ,
924- scandata = False , full = False , session = None ):
924+ scandata = False , full = False , session = None ,
925+ background = None ):
925926 """Validate a collection.
926927
927928 Returns a dict of validation info. Raises CollectionInvalid if
928929 validation fails.
929930
931+ See also the MongoDB documentation on the `validate command`_.
932+
930933 :Parameters:
931934 - `name_or_collection`: A Collection object or the name of a
932935 collection to validate.
@@ -938,9 +941,16 @@ def validate_collection(self, name_or_collection,
938941 documents.
939942 - `session` (optional): a
940943 :class:`~pymongo.client_session.ClientSession`.
944+ - `background` (optional): A boolean flag that determines whether
945+ the command runs in the background. Requires MongoDB 4.4+.
946+
947+ .. versionchanged:: 3.11
948+ Added ``background`` parameter.
941949
942950 .. versionchanged:: 3.6
943951 Added ``session`` parameter.
952+
953+ .. _validate command: https://docs.mongodb.com/manual/reference/command/validate/
944954 """
945955 name = name_or_collection
946956 if isinstance (name , Collection ):
@@ -950,8 +960,13 @@ def validate_collection(self, name_or_collection,
950960 raise TypeError ("name_or_collection must be an instance of "
951961 "%s or Collection" % (string_type .__name__ ,))
952962
953- result = self .command ("validate" , _unicode (name ),
954- scandata = scandata , full = full , session = session )
963+ cmd = SON ([("validate" , _unicode (name )),
964+ ("scandata" , scandata ),
965+ ("full" , full )])
966+ if background is not None :
967+ cmd ["background" ] = background
968+
969+ result = self .command (cmd , session = session )
955970
956971 valid = True
957972 # Pre 1.9 results
0 commit comments