Skip to content

Commit 7c77072

Browse files
authored
Merge pull request #86 from Tschuuuls/patch-1
Account for older MongoDB Versions
2 parents 42106cd + f3e65ae commit 7c77072

File tree

1 file changed

+47
-15
lines changed

1 file changed

+47
-15
lines changed

readme-vars.yml

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,31 +64,63 @@ app_setup_block: |
6464
Starting with version 8.1 of Unifi Network Application, mongodb 3.6 through 7.0 are supported.
6565
6666
**Make sure you pin your database image version and do not use `latest`, as mongodb does not support automatic upgrades between major versions.**
67+
68+
**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.**
6769
68-
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:
70+
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:
6971
7072
```js
7173
db.getSiblingDB("MONGO_DBNAME").createUser({user: "MONGO_USER", pwd: "MONGO_PASS", roles: [{role: "dbOwner", db: "MONGO_DBNAME"}]});
7274
db.getSiblingDB("MONGO_DBNAME_stat").createUser({user: "MONGO_USER", pwd: "MONGO_PASS", roles: [{role: "dbOwner", db: "MONGO_DBNAME_stat"}]});
7375
```
76+
77+
If you are using mongodb < 6.0, you can create a `init-mongo.sh` file with the following contents:
78+
```sh
79+
#!/bin/bash
80+
81+
mongo <<EOF
82+
use admin
83+
db.auth("${MONGO_INITDB_ROOT_USERNAME}", "${MONGO_INITDB_ROOT_PASSWORD}")
84+
use ${MONGO_DBNAME}
85+
db.createUser({
86+
user: "${MONGO_USER}",
87+
pwd: "${MONGO_PASS}",
88+
roles: [
89+
{ db: "${MONGO_DBNAME}", role: "dbOwner" },
90+
{ db: "${MONGO_DBNAME}_stat", role: "dbOwner" }
91+
]
92+
})
93+
EOF
94+
```
7495
7596
Being sure to replace the placeholders with the same values you supplied to the Unifi container, and mount it into your *mongodb* container.
7697
7798
For example:
78-
79-
```yaml
80-
unifi-db:
81-
image: docker.io/mongo:<version tag>
82-
container_name: unifi-db
83-
volumes:
84-
- /path/to/data:/data/db
85-
- /path/to/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
86-
restart: unless-stopped
87-
```
88-
89-
*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.*
90-
91-
*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.*
99+
MongoDB >= 6.0:
100+
```yaml
101+
unifi-db:
102+
image: docker.io/mongo:<version tag>
103+
container_name: unifi-db
104+
volumes:
105+
- /path/to/data:/data/db
106+
- /path/to/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
107+
restart: unless-stopped
108+
```
109+
MongoDB < 6.0:
110+
```yaml
111+
unifi-db:
112+
image: docker.io/mongo:<version tag>
113+
container_name: unifi-db
114+
volumes:
115+
- /path/to/data:/data/db
116+
- /path/to/init-mongo.sh:/docker-entrypoint-initdb.d/init-mongo.sh:ro
117+
restart: unless-stopped
118+
```
119+
120+
121+
*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.*
122+
123+
*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*
92124
93125
You can also run the commands directly against the database using either `mongo` (< 6.0) or `mongosh` (>= 6.0).
94126

0 commit comments

Comments
 (0)