On my Mac,`brew services start mongodb-community@4.2` starts mongod process in unknown port

It looks like you had a more recent version of mongod using the same data directory.

I see 3 ways out:

1 - If the data that is there IS IMPORTANT, install and run a 5.x version rather than 4.2

or

2 - If the data that is there IS IMPORTANT and you MUST run 4.2,

  • make a backup of the data directory for later retrieval
  • create a new directory /opt/homebrew/var/mongodb-4.2
  • change the configuration file to reflect the new dbPath

or

3 - If the data that is there IS NOT IMPORTANT and you must run 4.2

  • make a backup of the data directory for later retrieval just in case the data is more important than you thought
  • rename /opt/homebrew/var/mongodb to /opt/homebrew/var/mongodb-5.x
  • creaet a new directory /opt/homebrew/var/mongodb/
2 Likes