[0] Unhandled rejection MongoError: (Unauthorized) not authorized on admin to execute command { listIndexes: "sessions", cursor: { } }
[0] at MongoError.create (/Users/biggahd/Desktop/Mars-EMS-1/backend/node_modules/mongodb-core/lib/error.js:31:11)
[0] at queryCallback (/Users/biggahd/Desktop/Mars-EMS-1/backend/node_modules/mongodb-core/lib/cursor.js:212:36)
[0] at /Users/biggahd/Desktop/Mars-EMS-1/backend/node_modules/mongodb-core/lib/connection/pool.js:469:18
[0] at process.processTicksAndRejections (node:internal/process/task_queues:77:11)
I have enabled the listIndexes in a custom role on MongoDB Atlas, I've basically approved all of the operations and still I'm getting this error.
I'm using the oldest version of MongoDB. I been instructed as such. -> 2.0.14 (Maybe that is the problem?
I'm using the newset verion of Sails.js -> v1.5.7
Can someone please give me guidence to resolve this error message?
The short answer - don't use auto-migrations. It's convenient, but not recommended even by sails itself:
And considering you opted for custom roles, dev convenience is not the top priority anyway.
The long answer.
Sails tries to sync your models with the database. Since you define indices on model level, it tries to get indices from the database to calculate the delta and build the update commands.
Why does it try to do it on admin database - a big mystery, which would require a bit of debugging to do RCA. Likely some misconfiguration, but I couldn't find anything obvious in the repository with static code analysis.
If you are using free/shared Atlas tiers (M0, M2, M5), you won't have access to admin database regardless of roles.