Hey ,
I’m trying to add the expireAfterSeconds
parameter to our MongoDB instance. The full command i’m trying to run is…
import pymongo
client = pymongo.MongoClient(mongo_db_connection_string)
db = client[database_name]
result = db.command(
{
'setClusterParameter': {
'changeStreamOptions': {
'preAndPostImages': {
'expireAfterSeconds': expire_after_seconds
}
}
}
}
)
But I get this error…
OperationFailure: setClusterParameter may only be run against the admin database.
Then when I try to run it against the Admin database like this…
db = client['admin']
result = db.command(
{
'setClusterParameter': {
'changeStreamOptions': {
'preAndPostImages': {
'expireAfterSeconds': expire_after_seconds
}
}
}
}
)
I get this error…
not authorized on admin to execute command
So I can’t use the Database role I made (which has Atlas Admin privileges) to run this command, so I need another user/role. I tried authenticating with my own username and password (when I log into the Atlas Gui), and I have full access rights to the MongoDB project, but wasn’t able to run the command either…
import urllib.parse
from pymongo import MongoClient
username = urllib.parse.quote_plus("USERNAME")
password = urllib.parse.quote_plus("PASSWORD")
mongo_uri = f'mongodb+srv://{username}:{password}@CONNECTION_STRING_DETAILS/admin?retryWrites=true&w=majority'
client = MongoClient(mongo_uri)
db = client["admin"]
... etc ...
But got this error…
OperationFailure: Authentication failed., full error:
I seem to only be able to connect to my Project using a Database User, but I am unable to assign ClusterAdmin
to any Database Users - so I can’t run any commands on the admin database. So I thought I would connect with my user account that I log into MongoAtlas, but that authentication doesn’t work.
How can I connect to the Atlas database so that I can run setClusterParameter
commands?
This post is similar but was not resolved: MongoServerError: not authorized on admin to execute command - #3 by Hannes_Calitz
My question boils down to this:
- Am I able to run any commands on the admin database using MongoSH for a cluster hosted on MongoDB Atlas? My exploration seems like this is not possible, and instead to make edits through the gui.
I’m using MongoDB Atlas.
Any help or advice would be great.
Cheers,
Paul