|
| 1 | +# Install MongoDB Shell and Command Line Database Tools |
| 2 | + |
| 3 | +## Introduction |
| 4 | + |
| 5 | +This lab walks you through the steps to install MongoDB Shell and Command Line Database Tools to interact with Oracle Autonomous AI JSON Database collections through the Oracle Database API for MongoDB. |
| 6 | + |
| 7 | +**NOTE**: Mongo Shell and Tools are provided by MongoDB Inc. Oracle is not associated with MongoDB Inc, and has no control over the software. These instructions are provided simply to help you learn about Oracle Database API for MongodDB. Links may change without notice. |
| 8 | + |
| 9 | +Estimated Time: 15 minutes |
| 10 | + |
| 11 | +### About Oracle Database API for MongoDB |
| 12 | +Oracle Database API for MongoDB makes it possible to connect to Oracle Autonomous AI Database using MongoDB language drivers and tools. Oracle Database API for MongoDB leverages the converged database capabilities of an Autonomous AI Database to manage multiple data types, including JSON data, within a single database. |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +### Objectives |
| 17 | + |
| 18 | +In this lab, you will: |
| 19 | +* Install MongoDB Shell and MongoDB Command Line Database Tools on your local machine |
| 20 | +* Alternatively, you can install MongoDB Compass (GUI) |
| 21 | +* Set up your PATH to point to the MongoDB Shell and MongoDB Command Line Database Tools executable |
| 22 | + |
| 23 | +### Prerequisites |
| 24 | + |
| 25 | +This lab assumes you have: |
| 26 | +* A Mac OS/X machine (Intel or Apple hardware) or a Windows PC. |
| 27 | +* Access to the command prompt / terminal |
| 28 | + |
| 29 | +## Task 1: Open a terminal and determine the type of hardware (Mac only) or open command prompt (Windows only) |
| 30 | + |
| 31 | +1. (Mac only) Open the **Terminal** utility, type the following and press enter: |
| 32 | + |
| 33 | + ```bash |
| 34 | + <copy> |
| 35 | + uname -m |
| 36 | + </copy> |
| 37 | + ``` |
| 38 | + |
| 39 | +An output of `x86_64` indicates your Mac has an Intel processor; an output of `arm64` indicates your Mac has an Apple silicon processor (M1, M2, etc). You will use this to determine which version of Mongosh and MongoDB command line database tools to download. |
| 40 | + |
| 41 | +2. (Windows only) Open the **Command Prompt** utility. |
| 42 | + |
| 43 | +## Task 2: Download MongoDB shell and command line tools |
| 44 | + |
| 45 | +1. First, create and enter a suitable directory. Under the default home directory, create a directory called 'mongo'. For **Mac or Windows**, enter the following commands: |
| 46 | + |
| 47 | + ```bash |
| 48 | + <copy> |
| 49 | + mkdir mongo |
| 50 | + cd mongo |
| 51 | + </copy> |
| 52 | + ``` |
| 53 | + |
| 54 | +2. On both Mac and Windows, you can use the built-in 'curl' command to access a URL and download a file from it. The URL to use will vary according to the machine involved. |
| 55 | + |
| 56 | +3. Copy **ONE set** of the following *curl* commands and paste it to the command or terminal window: |
| 57 | + |
| 58 | + * For **Mac with Intel processor** (Terminal output `x86_64`): |
| 59 | + |
| 60 | + Download MongoDB Shell: |
| 61 | + |
| 62 | + ```bash |
| 63 | + <copy> |
| 64 | + curl https://downloads.mongodb.com/compass/mongosh-2.5.9-darwin-x64.zip -o mongosh.zip |
| 65 | + </copy> |
| 66 | + ``` |
| 67 | + |
| 68 | + Download Command Line Database Tools: |
| 69 | + |
| 70 | + ```bash |
| 71 | + <copy> |
| 72 | + curl https://fastdl.mongodb.org/tools/db/mongodb-database-tools-macos-x86_64-100.13.0.zip -o mongodbtools.zip |
| 73 | + </copy> |
| 74 | + ``` |
| 75 | + |
| 76 | + * For **Mac with Apple chip** (Terminal output `arm64`): |
| 77 | + |
| 78 | + Download MongoDB Shell: |
| 79 | + |
| 80 | + ```bash |
| 81 | + <copy> |
| 82 | + curl https://downloads.mongodb.com/compass/mongosh-2.5.9-darwin-arm64.zip -o mongosh.zip |
| 83 | + </copy> |
| 84 | + ``` |
| 85 | + |
| 86 | + Download Command Line Database Tools: |
| 87 | + |
| 88 | + ```bash |
| 89 | + <copy> |
| 90 | + curl https://fastdl.mongodb.org/tools/db/mongodb-database-tools-macos-arm64-100.13.0.zip -o mongodbtools.zip |
| 91 | + </copy> |
| 92 | + ``` |
| 93 | + |
| 94 | + * For **Windows**: |
| 95 | + |
| 96 | + Download MongoDB Shell: |
| 97 | + |
| 98 | + ```bash |
| 99 | + <copy> |
| 100 | + curl https://downloads.mongodb.com/compass/mongosh-2.5.9-win32-x64.zip -o mongosh.zip |
| 101 | + </copy> |
| 102 | + ``` |
| 103 | + |
| 104 | + Download Command Line Database Tools: |
| 105 | + |
| 106 | + ```bash |
| 107 | + <copy> |
| 108 | + curl https://fastdl.mongodb.org/tools/db/mongodb-database-tools-windows-x86_64-100.13.0.zip -o mongodbtools.zip |
| 109 | + </copy> |
| 110 | + ``` |
| 111 | + |
| 112 | +4. The previous step will have downloaded two zip files called mongosh.zip and mongodbtools.zip, which we need to expand. |
| 113 | + |
| 114 | + On **Mac or Windows**, run the following commands: |
| 115 | + |
| 116 | + ```bash |
| 117 | + <copy> |
| 118 | + mkdir -p mongosh | tar -xvf mongosh.zip -C mongosh --strip-components=1 |
| 119 | + </copy> |
| 120 | + ``` |
| 121 | + |
| 122 | + ```bash |
| 123 | + <copy> |
| 124 | + mkdir -p mongodbtools | tar -xvf mongodbtools.zip -C mongodbtools --strip-components=1 |
| 125 | + </copy> |
| 126 | + ``` |
| 127 | + **Note**: If you encounter any issues with the download or the version listed here, then please visit https://www.mongodb.com/try/download/shell or https://www.mongodb.com/try/download/database-tools to download the most recent shell for your operating system. All subsequent instructions continue to be the same. |
| 128 | + |
| 129 | + **Note**: tar is a built-in command in Windows 11 and recent Windows 10 builds. If for any reason it is not available, you will need to expand the zip file using Windows Explorer. On Mac, you could use the command 'unzip mongosh.zip' to the same effect. |
| 130 | + |
| 131 | +## Task 3: Set the PATH to include the mongosh executable |
| 132 | + |
| 133 | +1. On **Mac** (Intel or Apple silicon) run the following commands to set your path variable to include the location of the **mongosh** and **mongoimport** executable. |
| 134 | + |
| 135 | + ```bash |
| 136 | + <copy> |
| 137 | + export PATH=$(dirname `find \`pwd\` -name mongosh -type f`):$PATH |
| 138 | + </copy> |
| 139 | + ``` |
| 140 | + |
| 141 | + ```bash |
| 142 | + <copy> |
| 143 | + export PATH=$(dirname `find \`pwd\` -name mongoimport -type f`):$PATH |
| 144 | + </copy> |
| 145 | + ``` |
| 146 | + |
| 147 | +2. On **Windows** you can use the following command, assuming you created the 'mongosh' directory in your home directory. If you created it elsewhere, you'll need to edit the path command appropriately. |
| 148 | +
|
| 149 | + ``` |
| 150 | + <copy> |
| 151 | + for /f "delims=" %G in ('where /r "%cd%" mongosh.exe') do @set "PATH=%~dpG;%PATH%" & goto :eof |
| 152 | + </copy> |
| 153 | + ``` |
| 154 | +
|
| 155 | + ``` |
| 156 | + <copy> |
| 157 | + for /f "delims=" %G in ('where /r "%cd%" mongodbimport.exe') do @set "PATH=%~dpG;%PATH%" & goto :eof |
| 158 | + </copy> |
| 159 | + ``` |
| 160 | +
|
| 161 | +3. Test whether you can reach the mongosh executable file: |
| 162 | +
|
| 163 | + * in a Mac terminal: |
| 164 | + ``` |
| 165 | + <copy> |
| 166 | + cd $HOME/mongo |
| 167 | + </copy> |
| 168 | + ``` |
| 169 | + * in a Windows command prompt: |
| 170 | + ``` |
| 171 | + <copy> |
| 172 | + cd %USERPROFILE%/mongo |
| 173 | + </copy> |
| 174 | + ``` |
| 175 | + * in Mac or Windows: |
| 176 | + ``` |
| 177 | + <copy> |
| 178 | + mongosh --version |
| 179 | + </copy> |
| 180 | + ``` |
| 181 | +
|
| 182 | + Should output the version downloaded from mongodb in Task 2. |
| 183 | +
|
| 184 | +4. Test whether you can reach one of the mongodb tool's executables: |
| 185 | + |
| 186 | + * in a Mac terminal: |
| 187 | + ``` |
| 188 | + <copy> |
| 189 | + cd $HOME/mongo |
| 190 | + </copy> |
| 191 | + ``` |
| 192 | + * in a Windows command prompt: |
| 193 | + ``` |
| 194 | + <copy> |
| 195 | + cd %USERPROFILE%/mongo |
| 196 | + </copy> |
| 197 | + ``` |
| 198 | + * in Mac or Windows: |
| 199 | + ``` |
| 200 | + <copy> |
| 201 | + mongodbimport --version |
| 202 | + </copy> |
| 203 | + ``` |
| 204 | + |
| 205 | + Should output the version information downloaded from mongodb in Task 2. Your PATH variable will point to other executables in the same location as mongodbimport. |
| 206 | + |
| 207 | + **NOTE**: If steps 3 or 4 fail, you'll have to set your path manually to include the 'bin' directories from the zip files you just downloaded. If you close and reopen your terminal window, you will need to re-run this command. Alternatively, you can always navigate to the directory where you have extracted the software and run the shell with the relative path. |
| 208 | +
|
| 209 | +5. Keep the command or terminal window open for later use. If you close it and need to reopen it, you will need to set the PATH again according to the instructions above. |
| 210 | +
|
| 211 | +Mongo Shell is now set up on your PC or Mac. |
| 212 | +
|
| 213 | +## Task 4 (optional): Install MongoDB Compass, the GUI for MongoDB |
| 214 | +
|
| 215 | +1. Identify the appropriate MongoDB Compass download for your local machine on https://www.mongodb.com/docs/compass/install/?operating-system=linux&package-type=.deb#std-label-download-install, download and install it. MongoDB Compass offers you both a graphical user interface, as well as a built-in MongoDB shell. |
| 216 | +
|
| 217 | +This step is optional, so it is not described in more detail here, although the installation itself is intuitive and self-describing. |
| 218 | +
|
| 219 | +## Learn More |
| 220 | +
|
| 221 | +* [Using Oracle Database API for MongoDB](https://docs.oracle.com/en/cloud/paas/autonomous-database/serverless/adbsb/mongo-using-oracle-database-api-mongodb.html#GUID-8321D7A6-9DBD-44F8-8C16-1B1FBE66AC56) |
| 222 | +* [Oracle AI Database API for MongoDB](https://blogs.oracle.com/database/post/mongodb-api) |
| 223 | +
|
| 224 | +## Acknowledgements |
| 225 | +
|
| 226 | +* **Authors** - Hermann Baer |
| 227 | +* **Contributors** - Beda Hammerschmidt |
| 228 | +- **Last Updated By/Date** - Eileen Beck, November 2025 |
0 commit comments