Count the selected elements in the query. :param with_limit_and_skip (optional): take any :meth:`limit` or :meth:`skip` that has been applied to this cursor into account when getting the count
(self, with_limit_and_skip=False)
| 398 | return results[0] if return_one else results |
| 399 | |
| 400 | def count(self, with_limit_and_skip=False): |
| 401 | """Count the selected elements in the query. |
| 402 | |
| 403 | :param with_limit_and_skip (optional): take any :meth:`limit` or |
| 404 | :meth:`skip` that has been applied to this cursor into account when |
| 405 | getting the count |
| 406 | """ |
| 407 | # mimic the fact that setting .limit(0) in pymongo sets no limit |
| 408 | # https://www.mongodb.com/docs/manual/reference/method/cursor.limit/#zero-value |
| 409 | if ( |
| 410 | self._limit == 0 |
| 411 | and with_limit_and_skip is False |
| 412 | or self._none |
| 413 | or self._empty |
| 414 | ): |
| 415 | return 0 |
| 416 | |
| 417 | kwargs = ( |
| 418 | {"limit": self._limit, "skip": self._skip} if with_limit_and_skip else {} |
| 419 | ) |
| 420 | |
| 421 | if self._limit == 0: |
| 422 | # mimic the fact that historically .limit(0) sets no limit |
| 423 | kwargs.pop("limit", None) |
| 424 | |
| 425 | if self._hint not in (-1, None): |
| 426 | kwargs["hint"] = self._hint |
| 427 | |
| 428 | if self._collation: |
| 429 | kwargs["collation"] = self._collation |
| 430 | |
| 431 | count = count_documents( |
| 432 | collection=self._cursor.collection, |
| 433 | filter=self._query, |
| 434 | **kwargs, |
| 435 | ) |
| 436 | |
| 437 | self._cursor_obj = None |
| 438 | return count |
| 439 | |
| 440 | def delete(self, write_concern=None, _from_doc_delete=False, cascade_refs=None): |
| 441 | """Delete the documents matched by the query. |
no test coverage detected