Validate a collection. Returns a dict of validation info. Raises CollectionInvalid if validation fails. See also the MongoDB documentation on the `validate command`_. :param name_or_collection: A Collection object or the name of a collection to validate
(
self,
name_or_collection: Union[str, Collection[_DocumentTypeArg]],
scandata: bool = False,
full: bool = False,
session: Optional[ClientSession] = None,
background: Optional[bool] = None,
comment: Optional[Any] = None,
)
| 1353 | return self._drop_helper(name, session, comment) |
| 1354 | |
| 1355 | def validate_collection( |
| 1356 | self, |
| 1357 | name_or_collection: Union[str, Collection[_DocumentTypeArg]], |
| 1358 | scandata: bool = False, |
| 1359 | full: bool = False, |
| 1360 | session: Optional[ClientSession] = None, |
| 1361 | background: Optional[bool] = None, |
| 1362 | comment: Optional[Any] = None, |
| 1363 | ) -> dict[str, Any]: |
| 1364 | """Validate a collection. |
| 1365 | |
| 1366 | Returns a dict of validation info. Raises CollectionInvalid if |
| 1367 | validation fails. |
| 1368 | |
| 1369 | See also the MongoDB documentation on the `validate command`_. |
| 1370 | |
| 1371 | :param name_or_collection: A Collection object or the name of a |
| 1372 | collection to validate. |
| 1373 | :param scandata: Do extra checks beyond checking the overall |
| 1374 | structure of the collection. |
| 1375 | :param full: Have the server do a more thorough scan of the |
| 1376 | collection. Use with `scandata` for a thorough scan |
| 1377 | of the structure of the collection and the individual |
| 1378 | documents. |
| 1379 | :param session: a |
| 1380 | :class:`~pymongo.client_session.ClientSession`. |
| 1381 | :param background: A boolean flag that determines whether |
| 1382 | the command runs in the background. Requires MongoDB 4.4+. |
| 1383 | :param comment: A user-provided comment to attach to this |
| 1384 | command. |
| 1385 | |
| 1386 | .. versionchanged:: 4.1 |
| 1387 | Added ``comment`` parameter. |
| 1388 | |
| 1389 | .. versionchanged:: 3.11 |
| 1390 | Added ``background`` parameter. |
| 1391 | |
| 1392 | .. versionchanged:: 3.6 |
| 1393 | Added ``session`` parameter. |
| 1394 | |
| 1395 | .. _validate command: https://mongodb.com/docs/manual/reference/command/validate/ |
| 1396 | """ |
| 1397 | name = name_or_collection |
| 1398 | if isinstance(name, Collection): |
| 1399 | name = name.name |
| 1400 | |
| 1401 | if not isinstance(name, str): |
| 1402 | raise TypeError( |
| 1403 | f"name_or_collection must be an instance of str or Collection, not {type(name)}" |
| 1404 | ) |
| 1405 | cmd = {"validate": name, "scandata": scandata, "full": full} |
| 1406 | if comment is not None: |
| 1407 | cmd["comment"] = comment |
| 1408 | |
| 1409 | if background is not None: |
| 1410 | cmd["background"] = background |
| 1411 | |
| 1412 | result = self.command(cmd, session=session) |