skip to Main Content

Error Starting MongoDB via Homebrew Services

When I run MongoDB, I usually start it manually (i.e. it’s not part of my login startup items) and I’m good about stopping the service before I shutdown.

I recently restarted my laptop and received an error upon running:

brew services run mongodb/brew/mongodb-community

The error message reads:

Error: undefined method `plist_startup' for #<Formula mongodb-community (stable) /usr/local/Homebrew/Library/Taps/mongodb/homebrew-brew/Formula/mongodb-community.rb>

I’m not entirely sure what happened. I haven’t installed any major updates or made any modifications to my environment.

What I’ve Tried

I completely uninstalled MongoDB before installing it again:

# Uninstall each component of mongodb-community...
brew uninstall mongodb/brew/mongodb-community
brew uninstall mongodb/brew/mongodb-database-tools
brew uninstall mongosh

# Reinstall all of the above...
brew install mongodb/brew/mongodb-community

Current Install

mongodb --version

db version v7.0.2
Build Info: {
    "version": "7.0.2",
    "gitVersion": "02b3c655e1302209ef046da6ba3ef6749dd0b62a",
    "modules": [],
    "allocator": "system",
    "environment": {
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}

Could be Homebrew…?

I’ll be honest, sometimes on these late nights, I’m on autopilot. I may or may not have run a brew upgrade at some point. I’ll look into whether or not this happened. In the meantime, when I get the log for MongoDB in Homebrew, I don’t even see a commit that would have impacted me:

brew log mongodb/brew/mongodb-community

# Yields...

commit f33a59b6642f6a9f47f84b390dd71c386998cce6
Author: Zack Winter <[email protected]>
Date:   Wed Oct 4 23:24:26 2023 +0000

    Update paths with mr script

commit 7f3db6dbe9231300cc61645c68686a970b575f1f
Author: Zack Winter <[email protected]>
Date:   Tue Oct 3 20:00:06 2023 +0000

    SERVER-80537 update formulas for 7.0.1 release

commit 5055c34131148681885ea2241abccfc603596295
Author: Alexander Neben <[email protected]>
Date:   Fri Aug 18 10:54:02 2023 -0700
Anyone else seeing this?

Many thanks in advance!

2

Answers


  1. Chosen as BEST ANSWER

    Start Script Changed

    I'm not sure how or why, but it seems like the startup script had to change. Here are the steps I took to get MongoDB back up and running again, though I would recommend just skipping down to trying an alternative to starting MongoDB, first.

    Reinstall MongoDB

    I first tried forcing a reinstall of MongoDB, via Homebrew. My efforts, of course, were to no avail:

    brew reinstall mongodb/brew/mongodb-community
    

    Uninstalled Homebrew

    This was annoying because it basically disconnects itself from anything it ever installed. If you want to blast through updates as per usual, you'll have to reinstall everything again. It's easy enough to make a list and run a batch install:

    brew leaves
    

    But, be careful: that doesn't include all your casks. I forgot to make my list and check it twice this holiday season. If you want to have a nicely wrapped Homebrew, be sure to run this as well:

    brew list --cask   #add the "-1" to the end if you want a vertical list.
    

    Reinstalled An Old Version of Homebrew

    I went back and found the installer package for Homebrew-4.1.23.pkg and just installed via the GUI when I couldn't figure out how to install a previous version from a script.

    Unfortunately, before I ran any kind of brew install ... commands, I forgot to set this variable:

    export HOMEBREW_NO_AUTO_UPDATE=1;
    

    ....soooooo, ya. Once I ran any brew command it upgraded me right back to where I started thinking there was an issue. Aren't you glad you skipped to the end instead of following these steps?

    Alternate Method

    FWIW - When it came time to reinstall MongoDB, I followed a different path than I'm used to; different than what I have scripted for system setups. I used the method described in the MongoDB docs:

    brew install [email protected]
    

    Change MongoDB Startup Scripts

    In my profile script(s) I have a few functions for managing things like the start/stop of MongoDB. For example, my script to run MongoDB looks like this:

    function mongo-run {
        pid=$(ps -A | grep '[mon]god' | awk '{printf "%d", $1}');
        if [[ -z $pid ]];then
            brew services run mongodb/brew/mongodb-community;
        else
            printf "
            ${txtblu}Mongo is already running with process ID ${bldblu}$pid${txtrst}n";
        fi
    }
    

    ...and all I did was change to this:

    function mongo-run {
        pid=$(ps -A | grep '[mon]god' | awk '{printf "%d", $1}');
        if [[ -z $pid ]];then
            brew services run mongodb-community;
        else
            printf "
            ${txtblu}Mongo is already running with process ID ${bldblu}$pid${txtrst}n";
        fi
    }
    

    In case you missed it:

    
    # This...
    brew services run mongodb/brew/mongodb-community;
    
    # changed to this...
    brew services run mongodb-community;
    
    

    Pretty ridiculous, right?

    Oh well. It's all working again, for now.


  2. Oh my god, I meet the same problem.
    And I tried your solution, didn’t work.
    Seems there are some big bug, whether in Homebrew or MongoDB.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search