Python driver (pymongo) changeUserPassword() implementation

750 views
Skip to first unread message

Михаил Толмачев

unread,
Nov 9, 2013, 9:25:50 AM11/9/13
to mongod...@googlegroups.com
Hello! Is there in pymongo 2.6.3 implementation of function db.changeUserPassword() that required for mongodb >= 2.4 (my case is 2.4.8)?
Pymongo API documentation contain only addUser() function, that can not anymore update users's password.
How can I change user's password from my python script?

Bernie Hackett

unread,
Nov 9, 2013, 3:30:48 PM11/9/13
to mongod...@googlegroups.com
You can still use add_user to change the user's password:

>>> import pymongo
>>> c = pymongo.MongoClient()
>>> c.server_info()['version']
u'2.4.8'
>>> 
>>> pymongo.version
'2.6.3'
>>> 
>>> c.admin.add_user('admin', 'pass')
>>> c.admin.authenticate('admin', 'pass')
True
>>> c.admin.add_user('admin', 'newpass')
>>> c.admin.logout()
>>> c.admin.authenticate('admin', 'newpass')
True

What problem are you having?



--
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb
 
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Михаил Толмачев

unread,
Nov 10, 2013, 1:09:34 AM11/10/13
to mongod...@googlegroups.com
I am sorry! I was used db.addUser ( { } ) form from my script and got error, and now I see that there is add_user() form. Thank you.

воскресенье, 10 ноября 2013 г., 4:30:48 UTC+8 пользователь Bernie Hackett написал:

Jeff Lee

unread,
Nov 10, 2013, 9:28:48 AM11/10/13
to mongod...@googlegroups.com
Hey Bernie,

In the shell, prior to 2.4, addUser was used to both add new users as well as to change user passwords.

In 2.4, if you have a user with roles granted, you need to use the changeUserPassword helper to change the password otherwise you get a duplicate key violation exception.

Are there any plans to add a change_user_password function in pymongo?  I know it's a lot easier for me to remember if I do things the same way in all my tools.

Actually, I just filed an improvement ticket as well ( PYTHON-597 ).

Thanks!

Bernie Hackett

unread,
Nov 10, 2013, 1:47:14 PM11/10/13
to mongod...@googlegroups.com
See my response in PYTHON-597. You can use add_user to change a user password with PyMongo, even in MongoDB 2.4.8, even if they have roles. You can even change their roles. I put a few examples in the ticket.
Reply all
Reply to author
Forward
0 new messages