@@ -1067,7 +1067,18 @@ def current_op(self, include_all=False, session=None):
10671067 return self ._current_op (include_all , session )
10681068
10691069 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.
10711082
10721083 Returns one of (:data:`~pymongo.OFF`,
10731084 :data:`~pymongo.SLOW_ONLY`, :data:`~pymongo.ALL`).
@@ -1076,19 +1087,32 @@ def profiling_level(self, session=None):
10761087 - `session` (optional): a
10771088 :class:`~pymongo.client_session.ClientSession`.
10781089
1090+ .. versionchanged:: 3.12
1091+ Deprecated.
1092+
10791093 .. versionchanged:: 3.6
10801094 Added ``session`` parameter.
10811095
10821096 .. mongodoc:: profiling
1097+ .. _profile command: https://docs.mongodb.com/manual/reference/command/profile/
10831098 """
1099+ warnings .warn ("profiling_level() is deprecated. See the documentation "
1100+ "for more information" ,
1101+ DeprecationWarning , stacklevel = 2 )
10841102 result = self .command ("profile" , - 1 , session = session )
10851103
10861104 assert result ["was" ] >= 0 and result ["was" ] <= 2
10871105 return result ["was" ]
10881106
10891107 def set_profiling_level (self , level , slow_ms = None , session = None ,
10901108 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"})
10921116
10931117 :Parameters:
10941118 - `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,
11211145
11221146 .. versionchanged:: 3.12
11231147 Added the ``sample_rate`` and ``filter`` parameters.
1148+ Deprecated.
11241149
11251150 .. versionchanged:: 3.6
11261151 Added ``session`` parameter.
11271152
11281153 .. mongodoc:: profiling
1154+ .. _profile command: https://docs.mongodb.com/manual/reference/command/profile/
11291155 """
1156+ warnings .warn ("set_profiling_level() is deprecated. See the "
1157+ "documentation for more information" ,
1158+ DeprecationWarning , stacklevel = 2 )
1159+
11301160 if not isinstance (level , int ) or level < 0 or level > 2 :
11311161 raise ValueError ("level must be one of (OFF, SLOW_ONLY, ALL)" )
11321162
@@ -1147,17 +1177,34 @@ def set_profiling_level(self, level, slow_ms=None, session=None,
11471177 self .command (cmd , session = session )
11481178
11491179 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())
11511190
11521191 :Parameters:
11531192 - `session` (optional): a
11541193 :class:`~pymongo.client_session.ClientSession`.
11551194
1195+ .. versionchanged:: 3.12
1196+ Deprecated.
1197+
11561198 .. versionchanged:: 3.6
11571199 Added ``session`` parameter.
11581200
11591201 .. mongodoc:: profiling
1202+ .. _profiler output: https://docs.mongodb.com/manual/reference/database-profiler/
11601203 """
1204+ warnings .warn ("profiling_info() is deprecated. See the "
1205+ "documentation for more information" ,
1206+ DeprecationWarning , stacklevel = 2 )
1207+
11611208 return list (self ["system.profile" ].find (session = session ))
11621209
11631210 def error (self ):
0 commit comments