Get the options set on this collection. Returns a dictionary of options and their values - see :meth:`~pymongo.database.Database.create_collection` for more information on the possible options. Returns an empty dictionary if the collection has not been created yet.
(
self,
session: Optional[ClientSession] = None,
comment: Optional[Any] = None,
)
| 2867 | self.database.client._retryable_write(False, inner, session, _Op.UPDATE_SEARCH_INDEX) |
| 2868 | |
| 2869 | def options( |
| 2870 | self, |
| 2871 | session: Optional[ClientSession] = None, |
| 2872 | comment: Optional[Any] = None, |
| 2873 | ) -> MutableMapping[str, Any]: |
| 2874 | """Get the options set on this collection. |
| 2875 | |
| 2876 | Returns a dictionary of options and their values - see |
| 2877 | :meth:`~pymongo.database.Database.create_collection` for more |
| 2878 | information on the possible options. Returns an empty |
| 2879 | dictionary if the collection has not been created yet. |
| 2880 | |
| 2881 | :param session: a |
| 2882 | :class:`~pymongo.client_session.ClientSession`. |
| 2883 | :param comment: A user-provided comment to attach to this |
| 2884 | command. |
| 2885 | |
| 2886 | .. versionchanged:: 3.6 |
| 2887 | Added ``session`` parameter. |
| 2888 | """ |
| 2889 | dbo = self._database.client.get_database( |
| 2890 | self._database.name, |
| 2891 | self.codec_options, |
| 2892 | self.read_preference, |
| 2893 | self.write_concern, |
| 2894 | self.read_concern, |
| 2895 | ) |
| 2896 | cursor = dbo.list_collections(session=session, filter={"name": self._name}, comment=comment) |
| 2897 | |
| 2898 | result = None |
| 2899 | for doc in cursor: |
| 2900 | result = doc |
| 2901 | break |
| 2902 | |
| 2903 | if not result: |
| 2904 | return {} |
| 2905 | |
| 2906 | options = result.get("options", {}) |
| 2907 | assert options is not None |
| 2908 | if "create" in options: |
| 2909 | del options["create"] |
| 2910 | |
| 2911 | return options |
| 2912 | |
| 2913 | @_csot.apply |
| 2914 | def _aggregate( |
no test coverage detected