Skip to content

Commit cb61a95

Browse files
Bot Updating Templated Files
1 parent 7c77072 commit cb61a95

File tree

1 file changed

+47
-15
lines changed

1 file changed

+47
-15
lines changed

README.md

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,30 +68,62 @@ Starting with version 8.1 of Unifi Network Application, mongodb 3.6 through 7.0
6868

6969
**Make sure you pin your database image version and do not use `latest`, as mongodb does not support automatic upgrades between major versions.**
7070

71-
If you are using the [official mongodb container](https://hub.docker.com/_/mongo/), you can create your user using an `init-mongo.js` file with the following contents:
71+
**MongoDB >4.4 on X86_64 Hardware needs a CPU with AVX support. Some lower end Intel CPU models like Celeron and Pentium (before Tiger-Lake) more Details: [Advanced Vector Extensions - Wikipedia](https://en.wikipedia.org/wiki/Advanced_Vector_Extensions#CPUs_with_AVX) don't support AVX, but you can still use MongoDB 4.4.**
72+
73+
If you are using the [official mongodb container](https://hub.docker.com/_/mongo/) in Version >=6, you can create your user using an `init-mongo.js` file with the following contents:
7274

7375
```js
7476
db.getSiblingDB("MONGO_DBNAME").createUser({user: "MONGO_USER", pwd: "MONGO_PASS", roles: [{role: "dbOwner", db: "MONGO_DBNAME"}]});
7577
db.getSiblingDB("MONGO_DBNAME_stat").createUser({user: "MONGO_USER", pwd: "MONGO_PASS", roles: [{role: "dbOwner", db: "MONGO_DBNAME_stat"}]});
7678
```
7779

78-
Being sure to replace the placeholders with the same values you supplied to the Unifi container, and mount it into your *mongodb* container.
79-
80-
For example:
81-
82-
```yaml
83-
unifi-db:
84-
image: docker.io/mongo:<version tag>
85-
container_name: unifi-db
86-
volumes:
87-
- /path/to/data:/data/db
88-
- /path/to/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
89-
restart: unless-stopped
80+
If you are using mongodb < 6.0, you can create a `init-mongo.sh` file with the following contents:
81+
```sh
82+
#!/bin/bash
83+
84+
mongo <<EOF
85+
use admin
86+
db.auth("${MONGO_INITDB_ROOT_USERNAME}", "${MONGO_INITDB_ROOT_PASSWORD}")
87+
use ${MONGO_DBNAME}
88+
db.createUser({
89+
user: "${MONGO_USER}",
90+
pwd: "${MONGO_PASS}",
91+
roles: [
92+
{ db: "${MONGO_DBNAME}", role: "dbOwner" },
93+
{ db: "${MONGO_DBNAME}_stat", role: "dbOwner" }
94+
]
95+
})
96+
EOF
9097
```
9198

92-
*Note that the init script method will only work on first run. If you start the mongodb container without an init script it will generate test data automatically and you will have to manually create your databases, or restart with a clean `/data/db` volume and an init script mounted.*
99+
Being sure to replace the placeholders with the same values you supplied to the Unifi container, and mount it into your *mongodb* container.
93100

94-
*If you are using the init script method do not also set `MONGO_INITDB_ROOT_USERNAME`, `MONGO_INITDB_ROOT_PASSWORD`, or any other "INITDB" values as they will cause conflicts.*
101+
For example:
102+
MongoDB >= 6.0:
103+
```yaml
104+
unifi-db:
105+
image: docker.io/mongo:<version tag>
106+
container_name: unifi-db
107+
volumes:
108+
- /path/to/data:/data/db
109+
- /path/to/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
110+
restart: unless-stopped
111+
```
112+
MongoDB < 6.0:
113+
```yaml
114+
unifi-db:
115+
image: docker.io/mongo:<version tag>
116+
container_name: unifi-db
117+
volumes:
118+
- /path/to/data:/data/db
119+
- /path/to/init-mongo.sh:/docker-entrypoint-initdb.d/init-mongo.sh:ro
120+
restart: unless-stopped
121+
```
122+
123+
124+
*Note that the init script method will only work on first run. If you start the Mongodb container without an init script it will generate test data automatically and you will have to manually create your databases, or restart with a clean `/data/db` volume and an init script mounted.*
125+
126+
*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*
95127

96128
You can also run the commands directly against the database using either `mongo` (< 6.0) or `mongosh` (>= 6.0).
97129

0 commit comments

Comments
 (0)