MongoDB error in Ansible

Hi, I am installing mongodb on Ubuntu22(ec2) using ansible but getting error:

TASK [realtimedb : create mongodb admin user] *******************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: ‘Collection’ object is not callable. If you meant to call the ‘add_user’ method on a ‘Database’ object it is failing because no such method exists.

mongodb ver: 7.0.3
pymongo ver: 4.6

Ubuntu22 supports min version 6 and I tested that as well.With min pymongo version 4.4 (all features supported) it returns the same error. I know that add_user and authenticate methods were deprecated in previous versions but could you please help if there is any fix for this issue or workaround?

If you post your code someone might be able to help you.

See PyMongo 4 Migration Guide - PyMongo 4.6.0 documentation

1 Like

Taking a quick look at the module it looks like the dedicated commands were patched in 2020 so is it possible that an old version of community.mongodb collection is installed?

Some quick sleuthing shows add_user was not in 1.0.0 of the collection and is certainly not in the current version 1.6.3

Check your installed version ansible-galaxy collection list