Closed denis-ev closed 1 year ago
Thanks for opening your first issue here! Be sure to follow the relevant issue templates, or risk having this issue marked as invalid.
I had similar problem and root cause was mentioned in the logs. It was trying to use database unifi_stat and failing.
Search for messages that have something like:
not authorized on unifi_stat to execute command { listCollections
I've fixed that by adding unifi user to unifi_stat database in my mongo. And it is actually mentioned here: https://github.com/linuxserver/docker-unifi-network-application#setting-up-your-external-database
I had this issue after following the instructions for mongodb init - but found the permission for both DBs needed to be provisioned under the user in primary DB - it seems as the app will establish a common session to unifi
, but access both unifi
and unifi_stat
.
Bellow user setup fixed things for me,
db.getSiblingDB("unifi").createUser({user: "unifi", pwd: "yourpassword", roles: [{role: "readWrite", db: "unifi"}, {role: "readWrite", db: "unifi_stat"}]});
I'm using mongodb 6.0.10
I'll add here that readWrite
does not seem to be sufficient if you're trying to restore a backup. At least, it wasn't for me using mongo 4.4. With @neatherweb's modified command, I got the unifi-network-application image to at least show the web UI, but when I tried to restore my config, I found the following error in logs/server.log:
[2023-09-23 05:10:59,828] <webapi-3> ERROR system - Fail to restore com.mongodb.MongoCommandException: Command failed with error 13 (Unauthorized): 'not authorized on unifi to execute command { dropDatabase: 1, $db: "unifi", lsid: { id: UUID("e0e71c9d-2a01-49fd-b3b2-60fc7874d5ae") } }' on server mongo.database:27017. The full response is {"ok": 0.0, "errmsg": "not authorized on unifi to execute command { dropDatabase: 1, $db: \"unifi\", lsid: { id: UUID(\"e0e71c9d-2a01-49fd-b3b2-60fc7874d5ae\") } }", "code": 13, "codeName": "Unauthorized"}
Updating the role to use dbOwner
seemed to do the trick. I used db.updateUser('unifi', {roles: [{'role':'dbOwner','db':'unifi'},{'role':'dbOwner','db':'unifi_stat'}]});
(edit: I mistakenly typed dbAdmin
instead of dbOwner
here initially, oops).
Is there an existing issue for this?
Current Behavior
Expected Behavior
No response
Steps To Reproduce
new folder, trying to run
docker-compose up
this error comes up every single time.Environment