PyMongo Errors - Not Authorized to execute command { aggregate

I have a developer who’s trying to run a python script but is getting the following error:

pymongo.errors.OperationFailure: not authorized on db to execute command { aggregate: "enrollment", pipeline: [ { $lookup: { from: "program", localField: "programId", foreignField: "programId", .... { id: UUID("1fb99c09-22d4-48d2-838e-64c6a0bfdc59") }, $clusterTime: { clusterTime: Timestamp(1686673905, 227), signature: { hash: BinData(0, FC1576C7BC8A657F23C06554D40096C5CE316190), keyId: 7211160844858556522 } }, $db: "db" }', 'code': 13, 'codeName': 'Unauthorized', '...'

We created a user account that has the following permissions:
db_list_collection@admin
read@db.program

am I missing some permissions here? ideally I don’t want to give it full read permissions but just what it needs to execute the script. any and all help would be great!

Can you try providing the same user account with read permissions on the "enrollment" collection to see if it resolves the error?

Regards,
Jason

thanks, just did and same issue…not sure what’s going on!

Thanks for confirming Chris.

A few questions:

  1. Are you able to provide the full command being executed? Redact any personal or sensitive information being doing so.
  2. Is this being run on an Atlas cluster? If so, did you wait for the user permissions update to complete in the Atlas UI before testing the command again?

Regards,
Jason

aha! found out that there was an error in the command. After they gave me the full error output found out they were pointing to a collection that didn’t exist. appreciate the help!

1 Like

Great! Thanks for confirming the root cause Chris.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.