@@ -1067,7 +1067,18 @@ def current_op(self, include_all=False, session=None):
1067
1067
return self ._current_op (include_all , session )
1068
1068
1069
1069
def profiling_level (self , session = None ):
1070
- """Get the database's current profiling level.
1070
+ """**DEPRECATED**: Get the database's current profiling level.
1071
+
1072
+ Starting with PyMongo 3.12, this helper is obsolete. Instead, users
1073
+ can run the `profile command`_, using the :meth:`command`
1074
+ helper to get the current profiler level. Running the
1075
+ `profile command`_ with the level set to ``-1`` returns the current
1076
+ profiler information without changing it::
1077
+
1078
+ res = db.command("profile", -1)
1079
+ profiling_level = res["was"]
1080
+
1081
+ The format of ``res`` depends on the version of MongoDB in use.
1071
1082
1072
1083
Returns one of (:data:`~pymongo.OFF`,
1073
1084
:data:`~pymongo.SLOW_ONLY`, :data:`~pymongo.ALL`).
@@ -1076,19 +1087,32 @@ def profiling_level(self, session=None):
1076
1087
- `session` (optional): a
1077
1088
:class:`~pymongo.client_session.ClientSession`.
1078
1089
1090
+ .. versionchanged:: 3.12
1091
+ Deprecated.
1092
+
1079
1093
.. versionchanged:: 3.6
1080
1094
Added ``session`` parameter.
1081
1095
1082
1096
.. mongodoc:: profiling
1097
+ .. _profile command: https://docs.mongodb.com/manual/reference/command/profile/
1083
1098
"""
1099
+ warnings .warn ("profiling_level() is deprecated. See the documentation "
1100
+ "for more information" ,
1101
+ DeprecationWarning , stacklevel = 2 )
1084
1102
result = self .command ("profile" , - 1 , session = session )
1085
1103
1086
1104
assert result ["was" ] >= 0 and result ["was" ] <= 2
1087
1105
return result ["was" ]
1088
1106
1089
1107
def set_profiling_level (self , level , slow_ms = None , session = None ,
1090
1108
sample_rate = None , filter = None ):
1091
- """Set the database's profiling level.
1109
+ """**DEPRECATED**: Set the database's profiling level.
1110
+
1111
+ Starting with PyMongo 3.12, this helper is obsolete. Instead, users
1112
+ can directly run the `profile command`_, using the :meth:`command`
1113
+ helper, e.g.::
1114
+
1115
+ res = db.command("profile", 2, filter={"op": "query"})
1092
1116
1093
1117
:Parameters:
1094
1118
- `level`: Specifies a profiling level, see list of possible values
@@ -1121,12 +1145,18 @@ def set_profiling_level(self, level, slow_ms=None, session=None,
1121
1145
1122
1146
.. versionchanged:: 3.12
1123
1147
Added the ``sample_rate`` and ``filter`` parameters.
1148
+ Deprecated.
1124
1149
1125
1150
.. versionchanged:: 3.6
1126
1151
Added ``session`` parameter.
1127
1152
1128
1153
.. mongodoc:: profiling
1154
+ .. _profile command: https://docs.mongodb.com/manual/reference/command/profile/
1129
1155
"""
1156
+ warnings .warn ("set_profiling_level() is deprecated. See the "
1157
+ "documentation for more information" ,
1158
+ DeprecationWarning , stacklevel = 2 )
1159
+
1130
1160
if not isinstance (level , int ) or level < 0 or level > 2 :
1131
1161
raise ValueError ("level must be one of (OFF, SLOW_ONLY, ALL)" )
1132
1162
@@ -1147,17 +1177,34 @@ def set_profiling_level(self, level, slow_ms=None, session=None,
1147
1177
self .command (cmd , session = session )
1148
1178
1149
1179
def profiling_info (self , session = None ):
1150
- """Returns a list containing current profiling information.
1180
+ """**DEPRECATED**: Returns a list containing current profiling
1181
+ information.
1182
+
1183
+ Starting with PyMongo 3.12, this helper is obsolete. Instead, users
1184
+ can view the database profiler output by running
1185
+ :meth:`~pymongo.collection.Collection.find` against the
1186
+ ``system.profile`` collection as detailed in the `profiler output`_
1187
+ documentation::
1188
+
1189
+ profiling_info = list(db["system.profile"].find())
1151
1190
1152
1191
:Parameters:
1153
1192
- `session` (optional): a
1154
1193
:class:`~pymongo.client_session.ClientSession`.
1155
1194
1195
+ .. versionchanged:: 3.12
1196
+ Deprecated.
1197
+
1156
1198
.. versionchanged:: 3.6
1157
1199
Added ``session`` parameter.
1158
1200
1159
1201
.. mongodoc:: profiling
1202
+ .. _profiler output: https://docs.mongodb.com/manual/reference/database-profiler/
1160
1203
"""
1204
+ warnings .warn ("profiling_info() is deprecated. See the "
1205
+ "documentation for more information" ,
1206
+ DeprecationWarning , stacklevel = 2 )
1207
+
1161
1208
return list (self ["system.profile" ].find (session = session ))
1162
1209
1163
1210
def error (self ):
0 commit comments