@@ -921,12 +921,15 @@ def drop_collection(self, name_or_collection, session=None):
921
921
session = session )
922
922
923
923
def validate_collection (self , name_or_collection ,
924
- scandata = False , full = False , session = None ):
924
+ scandata = False , full = False , session = None ,
925
+ background = None ):
925
926
"""Validate a collection.
926
927
927
928
Returns a dict of validation info. Raises CollectionInvalid if
928
929
validation fails.
929
930
931
+ See also the MongoDB documentation on the `validate command`_.
932
+
930
933
:Parameters:
931
934
- `name_or_collection`: A Collection object or the name of a
932
935
collection to validate.
@@ -938,9 +941,16 @@ def validate_collection(self, name_or_collection,
938
941
documents.
939
942
- `session` (optional): a
940
943
: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.
941
949
942
950
.. versionchanged:: 3.6
943
951
Added ``session`` parameter.
952
+
953
+ .. _validate command: https://docs.mongodb.com/manual/reference/command/validate/
944
954
"""
945
955
name = name_or_collection
946
956
if isinstance (name , Collection ):
@@ -950,8 +960,13 @@ def validate_collection(self, name_or_collection,
950
960
raise TypeError ("name_or_collection must be an instance of "
951
961
"%s or Collection" % (string_type .__name__ ,))
952
962
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 )
955
970
956
971
valid = True
957
972
# Pre 1.9 results
0 commit comments