@@ -978,12 +978,38 @@ def _create_or_update_user(
978
978
979
979
def add_user (self , name , password = None , read_only = None , session = None ,
980
980
** kwargs ):
981
- """Create user `name` with password `password`.
981
+ """**DEPRECATED**: Create user `name` with password `password`.
982
982
983
983
Add a new user with permissions for this :class:`Database`.
984
984
985
985
.. note:: Will change the password if user `name` already exists.
986
986
987
+ .. note:: add_user is deprecated and will be removed in PyMongo
988
+ 4.0. Starting with MongoDB 2.6 user management is handled with four
989
+ database commands, createUser_, usersInfo_, updateUser_, and
990
+ dropUser_.
991
+
992
+ To create a user::
993
+
994
+ db.command("createUser", "admin", pwd="password", roles=["root"])
995
+
996
+ To create a read-only user::
997
+
998
+ db.command("createUser", "user", pwd="password", roles=["read"])
999
+
1000
+ To change a password::
1001
+
1002
+ db.command("updateUser", "user", pwd="newpassword")
1003
+
1004
+ Or change roles::
1005
+
1006
+ db.command("updateUser", "user", roles=["readWrite"])
1007
+
1008
+ .. _createUser: https://docs.mongodb.com/manual/reference/command/createUser/
1009
+ .. _usersInfo: https://docs.mongodb.com/manual/reference/command/usersInfo/
1010
+ .. _updateUser: https://docs.mongodb.com/manual/reference/command/updateUser/
1011
+ .. _dropUser: https://docs.mongodb.com/manual/reference/command/createUser/
1012
+
987
1013
:Parameters:
988
1014
- `name`: the name of the user to create
989
1015
- `password` (optional): the password of the user to create. Can not
@@ -997,14 +1023,17 @@ def add_user(self, name, password=None, read_only=None, session=None,
997
1023
:class:`~pymongo.client_session.ClientSession`.
998
1024
999
1025
.. versionchanged:: 3.6
1000
- Added ``session`` parameter.
1026
+ Added ``session`` parameter. Deprecated add_user.
1001
1027
1002
1028
.. versionchanged:: 2.5
1003
1029
Added kwargs support for optional fields introduced in MongoDB 2.4
1004
1030
1005
1031
.. versionchanged:: 2.2
1006
1032
Added support for read only users
1007
1033
"""
1034
+ warnings .warn ("add_user is deprecated and will be removed in PyMongo "
1035
+ "4.0. Use db.command with createUser or updateUser "
1036
+ "instead" , DeprecationWarning , stacklevel = 2 )
1008
1037
if not isinstance (name , string_type ):
1009
1038
raise TypeError ("name must be an "
1010
1039
"instance of %s" % (string_type .__name__ ,))
@@ -1036,19 +1065,27 @@ def add_user(self, name, password=None, read_only=None, session=None,
1036
1065
raise
1037
1066
1038
1067
def remove_user (self , name , session = None ):
1039
- """Remove user `name` from this :class:`Database`.
1068
+ """**DEPRECATED**: Remove user `name` from this :class:`Database`.
1040
1069
1041
1070
User `name` will no longer have permissions to access this
1042
1071
:class:`Database`.
1043
1072
1073
+ .. note:: remove_user is deprecated and will be removed in PyMongo
1074
+ 4.0. Use the dropUser command instead::
1075
+
1076
+ db.command("dropUser", "user")
1077
+
1044
1078
:Parameters:
1045
1079
- `name`: the name of the user to remove
1046
1080
- `session` (optional): a
1047
1081
:class:`~pymongo.client_session.ClientSession`.
1048
1082
1049
1083
.. versionchanged:: 3.6
1050
- Added ``session`` parameter.
1084
+ Added ``session`` parameter. Deprecated remove_user.
1051
1085
"""
1086
+ warnings .warn ("remove_user is deprecated and will be removed in "
1087
+ "PyMongo 4.0. Use db.command with dropUser "
1088
+ "instead" , DeprecationWarning , stacklevel = 2 )
1052
1089
cmd = SON ([("dropUser" , name )])
1053
1090
# Don't send {} as writeConcern.
1054
1091
if self .write_concern .acknowledged and self .write_concern .document :
0 commit comments