Closed metron2 closed 5 months ago
Thanks for opening your first issue here! Be sure to follow the relevant issue templates, or risk having this issue marked as invalid.
The readme is correct and it worked for a lot of people including several team members.
@metron2 were you perchance using the bitnami mongodb helm chart or image? I was having the same exact problem, even tried going back to a chart version that used a 6.x mongodb. Your suggestion resolved the issue for me.
I'm using mongo:7
currently and this resolved my problems with it. I tried to use the bitnami/mongodb chart instead but it didn't work either because it initializes two separate users.
To be honest, I dislike that chart already and I don't want a replicaset. I just wrote a deployment yaml for the official image instead. It was easier to change the initialization javascript to grant the same unifi user permission both databases. I found this advice on this repo but for a different version of mongodb.
Here's the deployment I'm using. I'm using fluxcd to automatically patch everything, but it's looking for mongo:7
tags.
apiVersion: v1
kind: ConfigMap
metadata:
name: mongodb-config
data:
init-db.js: |
db.getSiblingDB("unifi").createUser({user: "unifi", pwd: "password", roles: [{role: "dbOwner", db: "unifi"}, {role: "dbOwner", db: "unifi_stat"}]});
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongodb-deployment
spec:
replicas: 1
selector:
matchLabels:
app: mongodb
template:
metadata:
labels:
app: mongodb
spec:
containers:
- name: mongodb
image: mongo:7.0.11 # {"$imagepolicy": "default:mongo" }
env:
- name: MONGO_INITDB_ROOT_USERNAME
value: "root"
- name: MONGO_INITDB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
key: root
name: mongo-password
ports:
- containerPort: 27017
protocol: TCP
volumeMounts:
- name: mongodb-data
mountPath: /storage/mongodb # Host storage path
- name: config-volume
mountPath: /docker-entrypoint-initdb.d/
volumes:
- name: mongodb-data
persistentVolumeClaim:
claimName: mongodb-pvc
- name: config-volume
configMap:
name: mongodb-config
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
namespace: default
name: mongodb-pvc
spec:
storageClassName: local-path
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 50Gi
Looks like you guys missed this part in the readme:
If you are using the init JS method do not also set MONGO_INITDB_ROOT_USERNAME, MONGO_INITDB_ROOT_PASSWORD, or any other "INITDB" values as they will cause conflicts. Setting these variables for the .sh file is necessary
Locking this thread so as not to confuse other users with conflicting info.
Is there an existing issue for this?
Current Behavior
If you follow the current instructions, unifi can't connect to the unifi_stat database on startup. The correct init-db.js is:
db.getSiblingDB("unifi").createUser({user: "unifi", pwd: "password", roles: [{role: "dbOwner", db: "unifi"}, {role: "dbOwner", db: "unifi_stat"}]});
Expected Behavior
This should work
Steps To Reproduce
Follow the readme using mongo:7
Environment
CPU architecture
x86-64
Docker creation
Container logs