17
mongod

I got the following error

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

But if I use

brew services start mongodb

then mongo server can start.

To fix the mongod error

I found the similar error thread

Error while upgrading Mongodb from 3.2 to 3.6

So I downgraded to mongodb 3.6, and run

db.adminCommand( { setFeatureCompatibilityVersion: "3.6" } )

and then reinstall mongodb 4.0, I still have the same error when I run

mongodb

I still have to use

brew services start mongodb

to start mongodb

In command line, I run

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

It says featureCompatibilityVersion is 3.6

What else I need to do to satisfy "The data files need to be fully upgraded to version 3.6 "?

Thanks!

Papershine
  • 4,995
  • 2
  • 24
  • 48
searain
  • 3,143
  • 6
  • 28
  • 60
  • I suggest you to run purge command first to completely uninstall 3.6 and then start installing 4.0 from scratch... – Ashh Jul 08 '18 at 04:26
  • Thanks @AnthonyWinzlet. I downgraded mongodb to 3.2. and clean up all the versions. step by step, upgrade to 3.4, 3.6 and 4.0. if the error show up, then based on the version I am upgrading to. run db.adminCommand( { setFeatureCompatibilityVersion: "3.x" } ) Now finally it is updated to 4.0. Also in the previous upgrades, I lost a few databases. But now, after this step by step upgrades. I got these databases back too. – searain Jul 08 '18 at 05:45
  • 1
    Please don't add your answer in the question. Post an answer instead. – Papershine Jul 08 '18 at 05:55

3 Answers3

52

I need to downgrade MongoDB to 3.4. Clean up all the versions. Then upgrade to 3.6 and 4.0 step by step.

First of all, back up your /data/db, just in case.

The following steps are from my experience, I used brew to install/uninstall mongodb.

I followed the instruction from this thread, but run the following steps on iMac.

Error while upgrading Mongodb from 3.2 to 3.6

Uninstall your current mongodb

brew uninstall mongodb

Install mongodb 3.4 version

brew install mongodb@3.4

Start mongod 3.4 version (when you install the old version like above, you need the full path to run it.)

/usr/local/opt/mongodb@3.4/bin/mongod

Start mongo 3.4 version

/usr/local/opt/mongodb@3.4/bin/mongo

Run the important command

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

Quit

>quit();

Terminate the mongod

Find PID of mongod process using $ top

Kill the process by $ kill <PID> (the Mongo docs have more info on this)

Uninstall mongodb 3.4

brew uninstall mongodb@3.4

Repeat the above steps for 3.6

Install mongodb 3.6 version

brew install mongodb@3.6

Start mongod 3.6 version

/usr/local/opt/mongodb@3.6/bin/mongod

Start mongo 3.6 version

/usr/local/opt/mongodb@3.6/bin/mongo

Run the important command

> db.adminCommand( { setFeatureCompatibilityVersion: "3.6" } )

...

Last, after uninstall 3.6, then you can install the most current version, 4.x, you don't have to specify the @4.x etc., just

Install the most current version

brew install mongodb
searain
  • 3,143
  • 6
  • 28
  • 60
  • 1
    Excuse me, may you post more detail steps? – Ferris Aug 23 '18 at 10:19
  • 1
    Thanks for this! Just a heads up, you don't need to setFeatureCompatibilityVersion for 3.2 as it doesn't support that functionality. – martinedwards Mar 01 '19 at 11:58
  • Why do we have to do this? That's so many steps to just install – luckyging3r Apr 03 '19 at 20:16
  • **Make sure to run `setFeatureCompatibilityVersion` in correct database** Somehow I have homebrew setup with a different database (i.e. not `/data/db`). After running through this process, the default database (`/data/db`) was up to date and working, but running `brew services start mongodb` would not work. To fix, instead of running `/usr/local/opt/mongodb@3.4/bin/mongod`, I ran `brew services start mongodb@3.4`, and then `/usr/local/opt/mongodb@3.4/bin/mongo` to connect and setFeatureCompatibilityVersion. This made homebrew use the db that is setup with homebrew (`/data/otherDb`) – Danny Harding Aug 30 '19 at 18:02
  • A little addition, for everyone still stumbling over this issue. Mongodb is installed from their own sources now, there is no "mongodb" directly in brew anymore: https://www.mongodb.com/blog/post/mongodbs-official-brew-tap-now-open-and-flowing And the paths are also different (`mongodb-community` instead of just `mongodb` for the executeable) – maxigs Aug 21 '20 at 11:50
  • Same data files too old issue after I updated to mongodb-community@5.0. "mongod --config /usr/local/etc/mongod.conf" just would not start. I checked the log. find this error:msg":"This version of MongoDB is too recent to start up on the existing data files. Try MongoDB 4.2 or earlier.". I googled and found this thread: https://stackoverflow.com/questions/64141258/this-version-of-mongodb-is-too-recent-to-start-up-on-the-existing-data-files-tr. The dbpath is "/usr/local/var/mongodb" now – searain Dec 02 '21 at 19:47
1

I would better just do it via mongodump/mongorestore procedures.

WHITECOLOR
  • 24,996
  • 37
  • 121
  • 181
1

thx @searain, this procedure worked also on Ubuntu, I just had to adapt the commands, for those who are interested:

Commands for Ubuntu 16.04

Backup database and mongod.conf

sudo cp -rp /var/lib/mongodb/ mongobackup/

sudo cp -p /etc/mongod.conf mongobackup/

Uninstall v4

sudo service mongod stop

sudo apt purge mongodb-org*

Install v3.4

Copy installation commands from docs@v3.4

List available versions

sudo apt list -a mongodb-org

Install specific version

sudo apt install -y mongodb-org=3.4.22 mongodb-org-server=3.4.22 mongodb-org-shell=3.4.22 mongodb-org-mongos=3.4.22 mongodb-org-tools=3.4.22 --allow-downgrades

Start service

sudo systemctl enable mongod

sudo service mongod start

Login to mongo as admin

mongo -u "dba" -p "..." --authenticationDatabase "admin"

Issue command

Read more about setFeatureCompatibilityVersion in the docs.

db.adminCommand( { setFeatureCompatibilityVersion: "3.4" } )

If status is not ok but not authorized try:

db.grantRolesToUser('admin', [{ role: 'root', db: 'admin' }])

Uninstall v3.4

sudo service mongod stop

sudo apt purge mongodb-org*

Install v3.6

Copy installation commands from docs@v3.4

List available versions

sudo apt list -a mongodb-org

Install specific version

sudo apt install -y mongodb-org=3.6.14 mongodb-org-server=3.6.14 mongodb-org-shell=3.6.14 mongodb-org-mongos=3.6.14 mongodb-org-tools=3.6.14

Start service

sudo systemctl enable mongod

sudo service mongod start

Login to mongo as admin

mongo -u "dba" -p "..." --authenticationDatabase "admin"

Issue command

db.adminCommand( { setFeatureCompatibilityVersion: "3.6" } )

Uninstall v3.6

sudo service mongod stop

sudo apt purge mongodb-org*

Install v4

sudo apt install -y mongodb-org

Check config

During this process, the mongod.conf might have been lost. Make sure authorization is enabled:

sudo vi /etc/mongod.conf

Needs:

security:
  authorization: enabled

 Start service

sudo systemctl enable mongod

sudo service mongod start

Community
  • 1
  • 1
benjazehr
  • 145
  • 1
  • 7