Is it possible to create a shortcut in homebrew's name reference? - mongodb

I have installed mongodb using homebrew and can start the service using this command:
brew services start mongodb-community#4.2
is there a way to rename the mongodb-community or create an alias to be able to call it like this?
brew services start mongodb

If you are using bash then add following line in .bashrc file or if you are using zsh then add in .zshrc file
alias startmongo="mongod --config /usr/local/etc/mongod.conf"
Above command will run mongo in foreground and if you close the terminal, mongo process will exit,
but
if you are running
brew services start mongodb-community#4.2
this will run mongodb process in background as macos service.
Now
brew services start mongodb
Above command was in use before mongo 4.2 version.(some licensing changes after 4.0.5, do not know exact reason).
After 4.0.5, there is community and enterprise version of mongodb ref
So just to have two different service on same machine, command might have been changed for community version.
brew services start mongodb-community#4.2
Ref: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/#run-mongodb

just in case someone is wondering why dkb's solution is not working, you need to close the terminal and restart in order to see the changes.

Related

'mongo' is not recognized as an internal or external command, operable program or batch file [duplicate]

I installed MongoDB community Server from this link. But when I look into C:\Program Files\MongoDB\Server\6.0\bin
, I am not able to locate mongo.exe file. I am able to see mongod.exe and mongos.exe.
Can someone help. Thank you.
legacy mongo shell (mongo) no longer ships with server binaries (for servers >= 6.0). You can download a new shell version (mongosh) from here
Answer from dododo worked for me.
Download Mongo Shell - mongosh from MongoDB Download Center
Extract the contents of the bin from the downloaded zip file to the bin file of your MongoDB folder and run mongosh instead of mongo.
To run the Mongo Shell , Download msi package from the MongoDB Community Download - https://www.mongodb.com/try/download/community
The version 6.0 do not ships with server binaries so mongo.exe file wouldn't be shown. So instead download mongo shell - https://www.mongodb.com/try/download/shell
After downloading unzip the bin directory in your Original bin directory
(You would also need to create a new directory in C: drive named data/db)
Now open the bin directory from Mongodb folder, and run mongod.exe
After that keeping Mongod.exe running in background open mongosh.exe ,
Your mongo Shell will be started.
After version 6.0.0 mongo.exe does not get installed to your bin folder so you have to manually install the new MongoDB shell which is called mongosh then you have to add its path to your system variables and then run mongosh --version to see if it got installed. Afterwards if you want to create your own databases and preform operations run "mongosh" in your terminal to connect to a MongoDB instance running on your localhost with default port 27017.
Read the mongoDB documentation for more information:
install mongosh:
https://www.mongodb.com/docs/mongodb-shell/install/
The mongosh shell vs the old mongo shell:
https://www.mongodb.com/docs/mongodb-shell/
Connect to a Deployment:
https://www.mongodb.com/docs/mongodb-shell/connect/
It should be noted, that in MongoDB version 6.0 there are two items:
The legacy mongo shell is removed from MongoDB 6.0
The MongoDB Shell (mongosh) is not installed with MongoDB Server. You need to follow the mongosh installation instructions to download and install mongosh separately. This was already announced in MongoDB version 5.0
The legacy mongo shell does not exist anymore on MongoDB version 6.0. If you desire the old mongo.exe, then you can install if from an earlier MongoDB version.
You also need to add a path variable of the bin folder where mongosh application is present (after downloading from the below link:
https://www.mongodb.com/try/download/shell ).
Then you can use mongosh command from anywhere using CMD:
STEPS TO FOLLOW AFTER DOWNLOADING SHELL FROM https://www.mongodb.com/try/download/shell
Include both your mongosh shell and mongod in environment variables.
go to your c drive and create db folder inside data folder
then run your mongosh and mongod in two different cmd windows
separately
..first run mongod
..then run mongosh
if you have check-marked run as a service at the time of download
then next time you are not required to start mongosh , it will
automatically get started.

mongo.exe not installed in Version 6.0.0

I installed MongoDB community Server from this link. But when I look into C:\Program Files\MongoDB\Server\6.0\bin
, I am not able to locate mongo.exe file. I am able to see mongod.exe and mongos.exe.
Can someone help. Thank you.
legacy mongo shell (mongo) no longer ships with server binaries (for servers >= 6.0). You can download a new shell version (mongosh) from here
Answer from dododo worked for me.
Download Mongo Shell - mongosh from MongoDB Download Center
Extract the contents of the bin from the downloaded zip file to the bin file of your MongoDB folder and run mongosh instead of mongo.
To run the Mongo Shell , Download msi package from the MongoDB Community Download - https://www.mongodb.com/try/download/community
The version 6.0 do not ships with server binaries so mongo.exe file wouldn't be shown. So instead download mongo shell - https://www.mongodb.com/try/download/shell
After downloading unzip the bin directory in your Original bin directory
(You would also need to create a new directory in C: drive named data/db)
Now open the bin directory from Mongodb folder, and run mongod.exe
After that keeping Mongod.exe running in background open mongosh.exe ,
Your mongo Shell will be started.
After version 6.0.0 mongo.exe does not get installed to your bin folder so you have to manually install the new MongoDB shell which is called mongosh then you have to add its path to your system variables and then run mongosh --version to see if it got installed. Afterwards if you want to create your own databases and preform operations run "mongosh" in your terminal to connect to a MongoDB instance running on your localhost with default port 27017.
Read the mongoDB documentation for more information:
install mongosh:
https://www.mongodb.com/docs/mongodb-shell/install/
The mongosh shell vs the old mongo shell:
https://www.mongodb.com/docs/mongodb-shell/
Connect to a Deployment:
https://www.mongodb.com/docs/mongodb-shell/connect/
It should be noted, that in MongoDB version 6.0 there are two items:
The legacy mongo shell is removed from MongoDB 6.0
The MongoDB Shell (mongosh) is not installed with MongoDB Server. You need to follow the mongosh installation instructions to download and install mongosh separately. This was already announced in MongoDB version 5.0
The legacy mongo shell does not exist anymore on MongoDB version 6.0. If you desire the old mongo.exe, then you can install if from an earlier MongoDB version.
You also need to add a path variable of the bin folder where mongosh application is present (after downloading from the below link:
https://www.mongodb.com/try/download/shell ).
Then you can use mongosh command from anywhere using CMD:
STEPS TO FOLLOW AFTER DOWNLOADING SHELL FROM https://www.mongodb.com/try/download/shell
Include both your mongosh shell and mongod in environment variables.
go to your c drive and create db folder inside data folder
then run your mongosh and mongod in two different cmd windows
separately
..first run mongod
..then run mongosh
if you have check-marked run as a service at the time of download
then next time you are not required to start mongosh , it will
automatically get started.

mongodb-community not working on Apple M1

I've installed mongodb-community version 5.0 using brew, following this post's answer for M1 Apple Silicon Macs: How to install Mongodb on Apple M1 chip
Everything works fine, until the 6th step.
After running "mongo" in my terminal, I get the following errors.
I searched over stackoverflow and suspected that perhaps the mongodb service is not running, but the command "brew services list" gives the
following output.
Running "mongod" gives the following error.
Yet, checking "mongo --version" gives a clear indication of installation.
I have also uninstalled mongodb various times, started afresh with the whole procedure.
I'm so frustrated at this point. It would be really helpful if someone could let me know what's wrong in this process/how I could fix it.
PS: This is one of my first posts and I'm sorry if it is not structured well or does not follow a community guideline. I can try to edit the post if any rule is violated.
Thank you.
This solution worked for me
Read-only file system when attempting mkdir /data/db on Mac
rom the official docs https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/
Install homebrew and run the following commands
sudo chown -R $(whoami) $(brew --prefix)/*
then
brew tap mongodb/brew
then
brew install mongodb-community#4.2
and
brew services start mongodb-community
or
mongod --config /usr/local/etc/mongod.conf
then
ps aux | grep -v grep | grep mongod
and
mongo
to verify you can run show dbs in the mongo shell
Please follow this step for reinstalling mongodb, it works for me:
1st: run this command (Prerequisites)
xcode-select --install
\\note: Homebrew requires the Xcode commandline tools
2nd: install Homebrew for M1 chip (Prerequisites)
3rd: run this command to get Homebrew formula that work with mongodb
brew tap mongodb/brew
4th: run this command to get mongodb version 5
brew install mongodb-community#5.0
5th: run this command to run mongodb in the background
brew services start mongodb-community#5.0
// I notice that if I don't run this command I cannot connect to the server and receive the same error message like you
6th: just run mongo and enjoy. I hope it works.

Mongo command not found on Mac using zsh?

I installed Mongo Db via the official site. I also created the below folder
~/data/db
I added the mongo files in the location as follows :
/usr/local/mongodb
Im using zsh so setting the environment variables as suggested in the bash_profile doesnt work for me.
My .zshrc file looks as follows
export PATH=$HOME/bin:/usr/local/bin:$PATH
export MONGO_PATH=/usr/local/mongodb
export PATH=MONGO_PATH/bin:$PATH
I also ran the source command as follows :
source ~/.zshrc
However even after trying variations of various answers, I still get :
zsh: command not found: mongo
What am I missing here?
I have the same problem when I try to install Mongo with official doc
This instruction help me to run MongoDB on MacOS Mojave 10.14.6
Try mongod --version
If there is no Mongodb installed try enter brew install mongodb
After this check installation again with mongod --version
Then use brew services start mongodb to run MongoDB on startup
Try brew install mongodb-community-shell.
My case:
I did try brew services start mongodb to solve it, but face this issue:
Error: No available formula with the name "mongodb". Did you mean mongosh or monetdb?
Here is a recommendation on how to solve it where brew install mongodb-community-shell mentioed as part install of the latest Mongo shell: https://developpaper.com/fix-mac-brew-installation-mongodb-error-no-available-formula-with-the-name-mongodb/
this one worked for me.in new macbook or air we cant find .zhrc or bash
in new mac its .zprofile. so change the path in .zprofile
export PATH=/opt/homebrew/bin:$PATH
brew install mongodb-community-shell
you can try it it work for me because when downloading mongodb it lacks the shell so when typing mongo in terminal it won't work

How to install earlier version of mongodb with homebrew?

I'm on osx6.8 and need to install an earlier version of Mongodb, how do I install an earlier version with HomeBrew?
The below didn't work :(
dream-2:app2 star$ brew install mongodb-2.6.10
Error: No available formula for mongodb-2.6.10
Searching formulae...
Searching taps...
dream-2:app2 star$
Edit:
I'm getting a message to explain how this post is unique compared to another one, well, the answer to the other question is super long and complex and it's specific to postgresql and doesn't really answer my question.
Note: In September 2019 mongodb was removed from homebrew core, so these instructions have been updated to use mongodb-community instead, installed from the external tap.
If your current installation is still the pre-September mongodb package then you will need to use that name when you unlink, stop, relink and start, on the lines marked with #*# below.
Another option is to simply upgrade away from the deprecated package now.
I already have the latest version of mongo installed, thanks to.
brew tap mongodb/brew
brew install mongodb-community
But I want to switch to the old version sometimes. First, install it:
brew search mongo
brew install mongodb-community#3.2
Let's stop the current mongodb, if it is running:
brew services stop mongodb/brew/mongodb-community #*#
# or if you had started it manually
killall mongod
Now I want 3.2 on my PATH instead of the latest:
brew unlink mongodb-community #*#
brew link --force mongodb-community#3.2
(Apparently it needs --force because it is keg-only.)
Now I have 3.2 on my PATH, I can start the test DB:
mongod --version
brew services start mongodb/brew/mongodb-community
# or start your own mongod from the command-line
When I am finished, I can do the reverse to switch back to the latest version:
brew services stop mongodb/brew/mongodb-community
brew unlink mongodb-community#3.2
brew link mongodb-community #*#
brew services start mongodb/brew/mongodb-community #*#
And restart again.
When trying to install old versions of something with homebrew, it's usually useful to start with brew search packagename, in this case, there's a 2.6 version available under homebrew/versions/mongodb26
So, to install that version:
brew install homebrew/versions/mongodb26
Edit
This answer has certainly become very dated. Take a look at the answer below for a valid way to accomplish this in 2021.
curl -O https://fastdl.mongodb.org/osx/mongodb-osx-x86_64-3.2.12.tgz
tar -zxvf mongodb-osx-x86_64-3.2.12.tgz
mkdir -p mongodb
cp -R -n mongodb-osx-x86_64-3.2.12/ mongodb
export PATH=<mongodb-install-directory>/bin:$PATH #path to the dir created in step 3
mkdir -p /data/db
sudo chown -R $(whoami) /data/
mongod
Addition to the excellent answer of joeytwiddle :
if you don't want to link then unlink the old version of the software, you can just run it from the "cellar" (/usr/local/Cellar/), where brew installed it.
Use ls /usr/local/Cellar/ to find the exact path of the executable. For example in my case, to run mongo shell:
/usr/local/Cellar/mongodb#3.6/3.6.7/bin/mongo
Instead of using homebrew you can use docker to install as many versions of mongodb as you want. Each mongodb can then run on separate ports.
Install docker with brew cask install docker and then open Docker.app. After docker is running, go to Terminal and install your mongodb version by selecting an image from https://hub.docker.com/_/mongo/ like so: docker run -d -p 28017:27017 --name mongo4 mongo:latest
Verify that it's running with docker ps and you can connect to mongodb from your app using port 28017. Repeat the steps with a different name and port to install more versions. Enjoy!
I was able to install it using these instructions:
Installing MongoDB on OSX for local development
Over the last week, I’ve been building our MongoDB cluster on EC2 for
production. For development, however, we’ll still need to install
MongoDB locally. I’m running OSX 10.6.8, but these install
instructions should be the same on all modern OSX versions.
Installing on OSX is much more pleasant than on EC2 (actually it’s just as easy on EC2, but since it’s a simpler setup there’s n real configuration or
head scratching).
Download the latest binary:
curl -O http://fastdl.mongodb.org/osx/mongodb-osx-x86_64-2.0.2.tgz
Note!: If
you don’t have wget installed, simply download the file above by
visiting the link in your web browser and move it into your home
directory.
We’re going to install everything under /usr/local/mongodb
to keep things organized.
Create the directories (switch 'youruser' with your home user name):
sudo mkdir /usr/local/mongodb
sudo mkdir /usr/local/mongodb/log
sudo mkdir/usr/local/mongodb/data
sudo chown youruser /usr/local/mongodb/log
sudo chown youruser /usr/local/mongodb/data
sudo chgrp staff /usr/local/mongodb/log
sudo chgrp staff /usr/local/mongodb/data
Un-tar the binaries and move them into the correct folder:
tar -xvzf ~/mongodb-osx-x86_64-2.0.2.tgz
sudo mv ~/mongodb-osx-x86_64-2.0.2/* /usr/local/mongodb/
Create a config file for mongod:
sudo vi /usr/local/mongodb/mongod.conf
Paste:
dbpath=/usr/local/mongodb/data
logpath=/usr/local/mongodb/log/mongod.log
logappend=false
bind_ip=127.0.0.1
Note: dbpath and logpath specify the path to their
respective files, logappend is set to overwrite the log file on each
start of the database server, bind_ip only allows local connections.
Create an alias so that issuing mongod always read the config file:
vi ~/.profile
Paste:
# MongoDB Alias'
alias mongod="/usr/local/mongodb/bin/mongod --config=/usr/local/mongodb/mongod.conf"
All done, you should be able to simply type mongod after you reload the shell to start MongoDB. I
preferred not to start mongod on boot, but there are other who prefer
to and there’s plenty of documentation online to show you how to set
that up with launchd and creating a .plist.
http://alexanderwong.me/post/15259867190/installing-mongodb-on-osx-for-local-development
If you want to install an earlier MongoDB version on mac. Go to the link https://docs.mongodb.com/v3.6/tutorial/install-mongodb-on-os-x/ and select the version which you want to install and its very easy to install, just give a try. There will be around 2-3 commands for installation.
For example if you want to install version 3.6
brew tap mongodb/brew
brew install mongodb-community#3.6
If you got some error
If you need to have mongodb-community#3.6 first in your PATH run:
echo 'export PATH="/usr/local/opt/mongodb-community#3.6/bin:$PATH"' >> ~/.bash_profile
Then run
export PATH="/usr/local/opt/mongodb-community#3.6/bin:$PATH"
To confirm if it successfully installed:
mongod -version