Just a quick tip for those running the Ubiquiti UniFi Java controller on FreeBSD. If you've recently upgraded to the latest UniFi package ( pkg upgrade unifi5 ), it's likely that the version of MongoDB jumped from 3.2 to 3.6.

After you start the UniFi service, you're met with a loading WebUI screen and this in your log:

** IMPORTANT: UPGRADE PROBLEM: The data files need to be fully upgraded to version 3.4 before attempting an upgrade to 3.6; see http://dochub.mongodb.org/core/3.6-upgrade-fcv for more details.

Fixes simply state that you have to update the featureCompatabilityVersion and you're done. If, like me, you were on 3.2 and need to go to 3.6, you'll need to roll back to version 3.4:

pkg install mongodb34

pkg will ask you to uninstall unifi5 and downgrade you to mongodb34. You can safely do this without losing any data, but like any online disclaimer, backup or `zfs snapshot` is recommended regardless.

Most of the help I found online was missing this one key piece: the DB used when you service mongod start is not the same used by the UniFi controller. With that, once the install is complete, look at the UniFi logs, you'll see a line that looks similar to this:

<db-server> ERROR system - [exec] error, rc=100, cmdline=[bin/mongod, --dbpath, /usr/local/share/java/unifi/data/db, --port, 27117, --unixSocketPrefix, /usr/local/share/java/unifi/run, --logappend, --logpath, /usr/local/share/java/unifi/logs/mongod.log, --repair]

Copy and paste it to your command line, removing the commas and the --repair option:

mongod --dbpath /usr/local/share/java/unifi/data/db --port 27117 --unixSocketPrefix /usr/local/share/java/unifi/run --logappend --logpath /usr/local/share/java/unifi/logs/mongod.log --bind_ip 127.0.0.1

Then, from another terminal, connect:

mongo --port 27117

When you type the following, you'll see your featureCompatibilityVersion:

> db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )
{ "featureCompatibilityVersion" : { "version" : "3.2" }, "ok" : 1 }

This shows that we need to bring the featureCompatibilityVersion up to 3.4 before we jump to 3.6. Enter the following command while still in the mongo prompt:

> db.adminCommand( { setFeatureCompatibilityVersion: "3.4" } )
{ "ok" : 1 }
> exit

As long as you get an "ok", you should be good to upgrade. From the first terminal, ctrl-c out of the mongod standalone server and install unifi5 (this will automatically replace mongodb34 with mongodb36:

pkg install -y unifi5

Before starting the unifi service, upgrade the featureCompatibilityVersion to 3.6. Using the same command from above, start the standalone mongod service in one terminal while connecting from another:

  • Terminal 1:
mongod --dbpath /usr/local/share/java/unifi/data/db --port 27117 --unixSocketPrefix /usr/local/share/java/unifi/run --logappend --logpath /usr/local/share/java/unifi/logs/mongod.log --bind_ip 127.0.0.1
  • Terminal 2:
> db.adminCommand( { setFeatureCompatibilityVersion: "3.6" } )
{ "ok" : 1 }
> exit

Use ctrl-c to stop the database in terminal 1. At this point, you should be able to start the unifi service again. After starting  (service unifi start), you should see something like this in your logs:

[2018-12-26 13:21:19,907] <launcher> INFO  db     - setting mongodb features compatibility version to 3.6
[2018-12-26 13:21:19,908] <launcher> INFO  db     - DB version (5.8.24) different from Runtime Version(5.9.29), migrating...
[2018-12-26 13:21:19,914] <launcher> INFO  system - [server backup] started
[2018-12-26 13:21:19,915] <launcher> INFO  db     - Connecting to mongodb://127.0.0.1:27117
[2018-12-26 13:21:20,070] <launcher> INFO  db     - Connecting to mongodb://127.0.0.1:27117
[2018-12-26 13:21:20,138] <launcher> INFO  system - [server backup][BACKUP] end
[2018-12-26 13:21:20,218] <launcher> INFO  db     - DB migration to version (5.9.29) is complete.
[2018-12-26 13:21:20,827] <launcher> INFO  db     - Connecting to mongodb://127.0.0.1:27117

If you happened to follow guidance elsewhere telling you to run the --repair option, it's likely that the permissions are now incorrect. If this is the case, you'll see the following in your logs:

<launcher> INFO  system - [internal] unable to set file permission on /usr/local/share/java/unifi/data/db/admin.0: Operation not permitted

If this happens, just restore ownership to the unifi user:

chown -R unifi /usr/local/share/java/unifi/data/db/