Install MongoDB shell client without server

35,618

Solution 1

If you just want the mongo shell, you could install the mongodb-clients package mentioned in your question. However, note that this includes an older shell version (3.6.3).

The official MongoDB packages are updated with each minor release and you should ideally install a shell version matching your MongoDB server's major version (3.6, 4.0). Significant mismatches in shell versus server versions can result in some subtle errors as well as missing or outdated helpers. For example, the MongoDB 3.6.x shell doesn't have helpers for transactions (which were added in 4.0).

The MongoDB documentation includes information on Installing the official packages on Ubuntu. There is a mongodb-org-shell package which only includes the MongoDB shell, and you may also want to install mongodb-org-tools for other command-line tools (mongodump, mongorestore, ...).

It would be best to follow the instructions in the MongoDB documentation as some details may change in future (such as the signing key), but the general steps to follow for MongoDB 4.0 on Ubuntu 18.04 (Bionic) are:

  1. Import the public key used to sign packages from MongoDB, Inc

    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
    
  2. Create a package list file for MongoDB

    echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
    
  3. Update your local package database

    sudo apt-get update
    
  4. Install the desired MongoDB package(s)

    sudo apt-get install -y mongodb-org-shell
    

Solution 2

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 official website:

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

Share:
35,618

Related videos on Youtube

Vitaliy Terziev
Author by

Vitaliy Terziev

There are more stars in the Milky Way than loose change between your couch cushions. If you can’t solve a problem then there is an easier problem you can solve. Find it.

Updated on September 18, 2022

Comments

  • Vitaliy Terziev
    Vitaliy Terziev almost 2 years

    Where is the shell client for MongoDB, I found a number of packages related to MongoDB in Ubuntu 18.04 LTS but can't seem to find information where exactly is this client and what I should install.

    I know that if I install the MongoDB package the shell will be included but I don't need the server and other stuff because I have Atlas (cloud db server).

    Here are the links I found on the internet:

    Does it make sense going trough all the trouble above and should I simply install the MongoDB package?

  • Vitaliy Terziev
    Vitaliy Terziev over 5 years
    Thanks for your insights Stennie, I think this is exactly what I wanted to know!
  • Vitaliy Terziev
    Vitaliy Terziev over 5 years
    P.S. I ended up installing the clients package from Ubuntu reps, I always favor officially supported packages (by Ubuntu I mean, it's just easier most of the time) over installing from the internet, I needed it for testing purposes (the shell), 3.6.3 has the SSL and everything. However, I agree that in order to avoid as much issues as possible one should install recent versions of software (especially in production and stuff). And again - great and complete answer, very helpful!