Fixing MongoDB Compass Connection after upgrade

MongoDB

When upgrading MongoDB from an older version to the latest release, you might encounter connection errors in MongoDB Compass. This guide walks through the proper upgrade path to preserve your data while updating to the latest MongoDB version on MacOS Intel and Brew.

The problem

After upgrading MongoDB via Homebrew, Compass displays this error:

        
        
          
            
          
          
            
          
        

        LOCALHOST
connect ECONNREFUSED 127.0.0.1:27017
connect ECONNREFUSED ::1:27017
      

Checking the MongoDB logs reveals the real issue (tail -100 /usr/local/var/log/mongodb/mongo.log)

        
        
          
            
          
          
            
          
        

        UPGRADE PROBLEM: Found an invalid featureCompatibilityVersion document
Invalid feature compatibility version value '6.0'
Expected one of the following versions: '8.2', '8.1', '8.0'

      

MongoDB upgrade issues

MongoDB doesn't support jumping multiple major versions. If your data was created with MongoDB 6.0, you can't directly start it with MongoDB 8.x. The database requires incremental upgrades through each major version to properly migrate internal data structures.

Incremental Upgrade Path

The upgrade path from MongoDB 6.0 to 8.2 requires these steps:

  1. MongoDB 6.0 to 7.0
  2. MongoDB 7.0 to 8.0
  3. MongoDB 8.0 to 8.2

Each step involves installing the version, starting the server, and updating the Feature Compatibility Version (FCV) before moving to the next version.

Step-by-Step Upgrade Process

Stop Current MongoDB Service

        
        
          
            
          
          
            
          
        

        brew services stop mongodb-community
      

Uninstall Current Version

        
        
          
            
          
          
            
          
        

        brew uninstall mongodb-community
      

Upgrade to MongoDB 7.0

Install and Upgrade to MongoDB 7.0

        
        
          
            
          
          
            
          
        

        brew install [email protected]

      

Start the service:

        
        
          
            
          
          
            
          
        

        brew services start [email protected]

      

Wait a few seconds for the service to initialize, then upgrade the Feature Compatibility Version:

        
        
          
            
          
          
            
          
        

        mongosh --eval "db.adminCommand({ setFeatureCompatibilityVersion: '7.0', confirm: true })"

      

You should see: { ok: 1 }

Upgrade to MongoDB 8.0

Install MongoDB 8.0:

        
        
          
            
          
          
            
          
        

        brew install [email protected]
brew services start [email protected]
      

Wait for initialization, then upgrade FCV:

        
        
          
            
          
          
            
          
        

        mongosh --eval "db.adminCommand({ setFeatureCompatibilityVersion: '8.0', confirm: true })"

      

Upgrade to MongoDB 8.2

Stop and remove MongoDB 8.0:

        
        
          
            
          
          
            
          
        

        brew services stop [email protected]
brew uninstall [email protected]

      

Install the latest MongoDB:

        
        
          
            
          
          
            
          
        

        brew install mongodb-community
brew services start mongodb-community

      

Upgrade to the latest FCV:

        
        
          
            
          
          
            
          
        

        mongosh --eval "db.adminCommand({ setFeatureCompatibilityVersion: '8.2', confirm: true })"

      

Verify the Installation

Check that MongoDB is running and listening on the correct port:

        
        
          
            
          
          
            
          
        

        brew services list | grep mongodb
lsof -i :27017

      

You should see mongod listening on port 27017 for both IPv4 and IPv6.

Test the connection:

        
        
          
            
          
          
            
          
        

        mongosh --eval "db.adminCommand({ ping: 1 })"
      

Expected output: `{ ok: 1 }`

The connection should now work without errors, and all your existing databases and collections will be intact.

Alternative: Fresh Start

If you don't need your existing data, you can skip the incremental upgrade:

  1. Backup your data directory (usually `/usr/local/var/mongodb`)
  2. Stop MongoDB and remove the data directory
  3. Install the latest MongoDB version
  4. Start fresh with MongoDB 8.2