Issue a MongoDB command and parse the response as a cursor. If the response from the server does not include a cursor field, an error will be thrown. Otherwise, behaves identically to issuing a normal MongoDB command. :param command: document representing the command to be
(
self,
command: Union[str, MutableMapping[str, Any]],
value: Any = 1,
read_preference: Optional[_ServerMode] = None,
codec_options: Optional[CodecOptions[_CodecDocumentType]] = None,
session: Optional[ClientSession] = None,
comment: Optional[Any] = None,
max_await_time_ms: Optional[int] = None,
**kwargs: Any,
)
| 956 | |
| 957 | @_csot.apply |
| 958 | def cursor_command( |
| 959 | self, |
| 960 | command: Union[str, MutableMapping[str, Any]], |
| 961 | value: Any = 1, |
| 962 | read_preference: Optional[_ServerMode] = None, |
| 963 | codec_options: Optional[CodecOptions[_CodecDocumentType]] = None, |
| 964 | session: Optional[ClientSession] = None, |
| 965 | comment: Optional[Any] = None, |
| 966 | max_await_time_ms: Optional[int] = None, |
| 967 | **kwargs: Any, |
| 968 | ) -> CommandCursor[_DocumentType]: |
| 969 | """Issue a MongoDB command and parse the response as a cursor. |
| 970 | |
| 971 | If the response from the server does not include a cursor field, an error will be thrown. |
| 972 | |
| 973 | Otherwise, behaves identically to issuing a normal MongoDB command. |
| 974 | |
| 975 | :param command: document representing the command to be issued, |
| 976 | or the name of the command (for simple commands only). |
| 977 | |
| 978 | .. note:: the order of keys in the `command` document is |
| 979 | significant (the "verb" must come first), so commands |
| 980 | which require multiple keys (e.g. `findandmodify`) |
| 981 | should use an instance of :class:`~bson.son.SON` or |
| 982 | a string and kwargs instead of a Python `dict`. |
| 983 | |
| 984 | :param value: value to use for the command verb when |
| 985 | `command` is passed as a string |
| 986 | :param read_preference: The read preference for this |
| 987 | operation. See :mod:`~pymongo.read_preferences` for options. |
| 988 | If the provided `session` is in a transaction, defaults to the |
| 989 | read preference configured for the transaction. |
| 990 | Otherwise, defaults to |
| 991 | :attr:`~pymongo.read_preferences.ReadPreference.PRIMARY`. |
| 992 | :param codec_options: A :class:`~bson.codec_options.CodecOptions` |
| 993 | instance. |
| 994 | :param session: A |
| 995 | :class:`~pymongo.client_session.ClientSession`. |
| 996 | :param comment: A user-provided comment to attach to future getMores for this |
| 997 | command. |
| 998 | :param max_await_time_ms: The number of ms to wait for more data on future getMores for this command. |
| 999 | :param kwargs: additional keyword arguments will |
| 1000 | be added to the command document before it is sent |
| 1001 | |
| 1002 | .. note:: :meth:`command` does **not** obey this Database's |
| 1003 | :attr:`read_preference` or :attr:`codec_options`. You must use the |
| 1004 | ``read_preference`` and ``codec_options`` parameters instead. |
| 1005 | |
| 1006 | .. note:: :meth:`command` does **not** apply any custom TypeDecoders |
| 1007 | when decoding the command response. |
| 1008 | |
| 1009 | .. note:: If this client has been configured to use MongoDB Stable |
| 1010 | API (see `versioned API <https://www.mongodb.com/docs/manual/reference/stable-api/#what-is-the-stable-api--and-should-you-use-it->`_), then :meth:`command` will |
| 1011 | automatically add API versioning options to the given command. |
| 1012 | Explicitly adding API versioning options in the command and |
| 1013 | declaring an API version on the client is not supported. |
| 1014 | |
| 1015 | .. seealso:: The MongoDB documentation on `commands <https://dochub.mongodb.org/core/commands>`_. |