As mentioned above, I need to install only the mongo shell on a RHEL instance (machine A).
I have a mongodb server on a separate instance (machine B) and need to connect to that from A to run mongodump and mongorestore commands.
I tried looking it up on the web but all I got was instructions to install the complete mongodb package.
Any help appreciated.
Official documentation says that you should be fine installing mongodb-org-shell only.
Create a repository file at sudo vim /etc/yum.repos.d/mongodb.repo
[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc
gpgcheck=1
enabled=1
sudo yum clean all
sudo yum install mongodb-org-shell-4.0.2
mongo <mongo-server-ip> Note: Step 4 will not work in all cases. You need to check proper command to connect to remote mongo server.
Source: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/
You can follow the official tutorial on installing mongodb, and instead of installing the main package that will install all the packages, just install the package containing mongoshell
Please follow below steps.
Create a file /etc/yum.repos.d/mongodb.repo
Update the above file to contain:
[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1
sudo yum install -y mongodb-org-shell-2.6.9
mongo mongo-db_server_IP:27017/database_name -u username -p password
You might want to install mongosh (MongoDB Shell) instead. The legacy mongo shell has been deprecated since MongoDB v5.0 and replaced by mongosh. From the mongosh docs:
The new MongoDB Shell, mongosh, offers numerous advantages over the
legacy mongo shell, such as:
Improved syntax highlighting.
Improved command history.
Improved logging.
Currently mongosh supports a subset of the mongo shell
methods. Achieving feature parity between mongosh and the mongo shell
is an ongoing effort.
To maintain backwards compatibility, the methods that mongosh supports
use the same syntax as the corresponding methods in the mongo shell.
To see the complete list of methods supported by mongosh, see MongoDB
Shell Methods.
Further reference: Compatibility Changes with Legacy mongo Shell
Head to Mongo download page; download your required package regarding your operating system. Finally follow the instruction of your operating system to install the package.
Especially to install mongo or mongosh:
download .tgz file and untar the file into /usr/local/
add /usr/local/mongo/ into the shell profile (e.g. ~/.bashrc) and restart your terminal
For more information read the docs.
P.S.: mongo in the path should be vary based on the version of the downloaded package.
Related
I run a MongoDB replica set in a containerization environment orchestrated by Rancher.
After rolling out the latest update, MongoDB as been upgraded from 3.6.x to 4.0.x (latest).
No upgrade path has been followed and, as a result, when trying to bind the volume holding the database storage, the service fails to start, exiting with the following exception:
STORAGE [initandlisten] exception in initAndListen: MustDowngrade: Collection does not have UUID in KVCatalog. Collection: admin.system.version, terminating
I get the same outcome even attempting to launch mongod with the --repair option.
I have also tried to rollback the container to MongoDB 3.6.16, but the journal version is now incompatible.
We don't have snapshots of the volume, hence restoring the data is not an option (this is not a production environment). The only solution I've found online is not applicable, since it suggests to leverage mongodump and mongorestore, requiring a running database with the data storage attached.
I'm running out of ideas, any advice about how to fix this?
A bug report on this issue recommended following the full upgrade path and that worked for me. I was able to go back to my old version when I ran into this error, and then upgrade properly.
Specifically: upgrade just one major version at a time and check the prerequisites and upgrade steps carefully. The most important part of this is checking your compatibility with db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } ) and make sure it matches the current version before upgrading to the next version. Update it with command like db.adminCommand( { setFeatureCompatibilityVersion: "3.6" } )
Read the full docs at pages like https://docs.mongodb.com/manual/release-notes/3.6/#upgrade-procedures https://docs.mongodb.com/manual/release-notes/4.0/#upgrade-procedures etc
I was updating MongoDB from 3.6 to 4.2 with Homebrew on Mac OS, and ran into this similar situation.
Since formula mongodb was removed from homebrew-core, the team of mongodb maintained a custom Homebrew tap.
Following steps is my solution for upgrading MongoDB from 3.6 to 4.2 with Homebrew:
Uninstall old version mongodb from Homebrew
# If you run mongodb in background service, stop it first.
brew services stop mongodb
# If you have multiple version of mongodb, you might need to add `--force` option for deleting all of them at once.
brew uninstall mongodb
Install new mongodb from custom Homebrew tap
brew tap mongodb/brew
brew install mongodb-community#3.6
Add mongodb-community#3.6 to your PATH
echo 'export PATH="/usr/local/opt/mongodb-community#3.6/bin:$PATH"' >> ~/.bash_profile
Restart your terminal, and run mongod
Open another tab or terminal windows to run mongodump
Terminate mongod
Uninstall mongodb-community#3.6 and reinstall mongodb-community
brew uninstall mongodb-community#3.6
brew install mongodb-community
Delete old data with old mongo data structure
rm -rf /data/db/*
Run mongod
Open another tab or terminal windows to run mongorestore dump/
Once mongorestore completed, mongod will be terminated.
And you can run mongodb as a background service or just run mongod again. Open MongoDB with mongo or Robo 3T(formerly Robomongo), you will see your data is good as usual.
Hope it helps.
Alright after about 3hours of trying to fix exactly what you are describing, here are the steps I took. Here I will show how to retain the data while downgrading to 3.6 and also how to update it 4.0 with the retained data.
The reason this happens for mac users is because there was an update for people using brew can no longer download Mongodb directly from brew. Then people tend to download the newer community edition instead from brew which then gets in conflict the old version of 3.6 db folder still present in the directory. Instead you would need to download it from the actual mongodb website:
https://www.mongodb.com/download-center/community
Here what you would want to do, is download everything manually. Follow these instructions here, but do this with the 3.6 version:
https://medium.com/#saurabhkumar_4718/install-mongodb-without-homebrew-on-mac-os-2a98b68ab09c
NOTE: when you copy .bash_profile please make sure export commands are not
Once you have successfully installed 3.6 manually you can mongodump to be safe, and or export all your mongo data into json with mongoexport for any data that you must really really save.
After that you can fresh install 4.0 manually again by following exactly the same steps as previously done for 3.6
This worked for me without having to do any 'mongorestore' as the 'db' folder was left alone and all my data was there, but maybe extra steps might be needed to restore the data. Worst comes to worst you have .jsons that needs to be rewritten. 'mongo --version' also showed the right version :) Hope it helps
Backing-up all the databases (using mongodump)
Removing every file in /data/db, due to their incompatibility with the newer version: rm -rf /data/db/*
Restarting the MongoDB service by mongod
Restoring all the databases (using mongorestore)
https://dba.stackexchange.com/a/252393
For Docker:
I had this issue when I was upgrading a project that used Docker from 3.6 to 4.2 (and 4.4).
The way the project is set up means I don't have a physical /data/db directory to purge.
However, there is a volume defined that acts as the /data/db directory.
In this case all you need to do is backup any data you need and remove the associated volume.
If using vs code with the docker extension, you can simply open your docker tab in the sidebar, expand the volumes section, locate the volume in question (for me it was called mongo-4-2-upgrade-test_mongo-data which depends on how your various containers are named for your project), right-click and remove.
Ensure that the containers that use this volume have been properly shut down or you'll get a 409 conflict error. I did the same as above but found my mongo container (in the containers section of the docker tab) instead. then when I restarted my docker-compose file the new version of mongo was installed and ran as expected.
I'm facing difficulties installing the MongoDB community server on Manjaro Linux.
There isn't official documentation on how to install it on Arch-based systems and Pacman can't find it in the AUR repos.
Has anyone ever tried to install it?
Here is what I did to install.
As the package is not available in the official Arch repositories and can't be installed using pacman, you need to follow a few steps to install it.
First, you need to get the URL for the repo of prebuilt binaries from AUR. It can be found here and by the time of writing this it was https://aur.archlinux.org/mongodb-bin.git
Simply clone the repo in your home directory or anywhere else. Do git clone https://aur.archlinux.org/mongodb-bin.git, then head to the cloned directory, cd mongodb-bin.
Now, all you need to do is to run makepkg -si command to make the package. the -s flag will handle the dependencies for you and the -i flag will install the package.
After makepkg finishes its execution, don't forget to start mongodb.service. Run systemctl start mongodb and if needed enable it with systemctl enable mongodb.
Type mongo in the terminal and if the Mongo Shell runs you are all set.
Later edit (8.2.2021): This package is now available in AUR.
It is available in AUR, so you can view it with pamac with -a flag,
eg.
pamac search -a mongodb-bin
pamac info -a mongodb-bin
And, then build and install with (this can be done after manually cloning too) -
pamac build mongodb-bin
Note that there's also a package named mongodb, but mongodb-bin is a newer release (you can check the version numbers by search or info arguments)
I've been using mongodb via docker for a couple of years.
In my experience, it's easier than installing the regular way. (assuming you already have docker installed)
1. Ensure you have docker installed
If you don't already have it, you can install via pacman/pamac, because it's in the official Arch/Manjaro package repositories. The easiest way is to run the following command:
sudo pacman -S docker
2. Run a single docker command
sudo docker run -d -p 27017:27017 -v ~/mongodb_data:/data/db mongo
This command will run mongodb on a port 27017, and place its data files into a folder ~/mongodb_data.
If you're running this command for the first time, it will also download all the required files.
Now you're successfully running a local instance of mongodb, and you can connect it with your favorite db management tool or from your code.
I installed MongoDB manually on the MongoDB website. https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/
I followed the instructions under "Install MongoDB Community Edition Manually".
How do I uninstall MongoDB completely? I have searched around and only found how to uninstall using Homebrew. I did not install MongoDB using Homebrew.
Any help is greatly appreciated.
Just follow the manual install steps in reverse order:
shutdown mongod
remove your data directory (if you no longer want this)
remove the directory with the MongoDB binaries
remove the directory with the MongoDB binaries from your shell PATH
Other files that might have been created depending on how you ran MongoDB:
there may be old log files to remove if you specified a --logpath outside your data directory
there may be a launchctl script and configuration file to remove if you configured mongod to run as a service
I first ran brew install mongodb, which successfully completed and installed version 3.4.4. I was then able to start the server using brew services start mongodb, and access the shell via running mongo.
Then I discovered I need mongodb version 3.2.0. I uninstalled mongo v3.4.4 via brew uninstall mongodb and verified service was gone and bin files removed.
I then ran brew search mongodb and found mongodb#3.2 in the list, and so ran brew install mongodb#3.2. This completed successfully, and I was able to start the server using brew services start mongodb#3.2, which is successful. I then go to access the shell via 'mongo', or 'mongo#3.2' or 'mongo32' and none of these exist.
What should this bin file be named and why can't I find it? with v3.4.4 shell bin executable was /usr/local/bin/mongo - this file doesn't exist after installing 'mongodb#3.2'.
I see it in /usr/local/Cellar/mongodb#3.2/3.2.11/bin/ along with all the other binaries.
I don't know why it isn't symlinked to /usr/local/bin/ like most other programs.
So I've followed the Mongodb installation instructions here: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/. However, after installing, mongodb does not run when invoked with start mongodb or /etc/init.d/mongodb start. After digging around and adding debug comments to /lib/init/upstart (!) I deduced that the problem is that the mongodb-10gen package inexplicably doesn't create an /usr/bin/mongodb executable for upstart to reference - it creates a bunch of other executables, but not that one. What's going on? Is the 10gen package broken? Are the instructions wrong? Or is something really, really, really bizarre going on on my system?
P.S. Installing the mongodb package included with Ubuntu 12.04 works like a charm.
Is there mongod executable?
If there is correct config in /etc/conf.d/mongod.conf or /etc/mongo/mongod.conf or something similar, you may start server by running mongod -f /etc/mongo/mongod.conf.
If there is no correct config, just write it by yourself. http://docs.mongodb.org/manual/reference/configuration-options/
My config.
Also, if there is error with missing /usr/bin/mongodb, you may just create symlink from /usr/bin/mongodb to /usr/bin/mongod by executing following (with root privileges):
# ln -s /usr/bin/mongod /usr/bin/mongodb