October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk8 min

How to Access the MongoDB Shell on a Linux VPS

A practical guide to opening mongosh on a Linux VPS, choosing the right host and port, authenticating securely, enabling TLS, selecting a database, verifying the connection, and troubleshooting failures.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

SSH into the VPS, make sure the current MongoDB Shell (mongosh) is installed, and run mongosh. With no options, it connects to MongoDB on localhost:27017. The same connection written as a URI is mongosh "mongodb://localhost:27017". From there, use the appropriate host, port, credentials, TLS option, and database name for your deployment.

What you need before opening the shell

mongosh is a command-line client. It does not install MongoDB or start the database server; it connects to a deployment that is already running. MongoDB’s documented connection procedures assume that the shell is installed before you begin.

As an Amazon Associate I earn from qualifying purchases.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • An SSH account that can reach the Linux VPS.
  • The mongosh executable installed on the VPS, or on another machine from which you will connect.
  • The deployment’s hostname or IP address and listening port.
  • Credentials and the authentication database when access control is enabled.
  • Any TLS requirements, certificate material, replica-set details, or cloud connection URI required by the deployment.

After connecting over SSH, check that the command is available. Running mongosh --version is a quick way to confirm that the shell can be invoked. If the command is missing, install the MongoDB Shell package appropriate for your Linux distribution and then reconnect or open a new terminal so the executable is on your PATH. The shell version and the MongoDB server version are separate concerns: installing mongosh gives you the client, while the server must still be running and reachable.

The fastest connection: MongoDB on the same VPS

For the common case in which MongoDB runs on the VPS you have just entered, use:

#1 Best Overall
Sale
TOZO A1 Wireless Earbuds Bluetooth 5.3 Light Weight in Ear Headphones | IPX5 Waterproof,2 Mics for AI Calls,Immersive Premium Sound Bass Headset with Charging Case,32 EQ via App Black
  • [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
  • [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
  • [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
  • [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
  • [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.
mongosh

With no options, mongosh targets localhost on port 27017. This is equivalent to:

mongosh "mongodb://localhost:27017"

A successful connection opens an interactive prompt. Commands entered there are evaluated against the connected deployment. If your server uses a different port, or if the process is not listening on the local default, the no-option form will fail even though MongoDB may be running.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the connection form that matches your deployment

Situation Command form What it selects
Local deployment on the default port mongosh localhost:27017
Local deployment on another port mongosh "mongodb://localhost:28015" or mongosh --port 28015 Local host, port 28015
Named host and port in a URI mongosh "mongodb://mongodb0.example.com:28015" The host and port written in the URI
Named host and port as options mongosh --host mongodb0.example.com --port 28015 The host and port supplied as separate options
Authentication enabled mongosh "mongodb://mongodb0.example.com:28015" --username alice --authenticationDatabase admin The deployment, user alice, and authentication database admin
TLS required Add --tls, or add ?tls=true to the URI An encrypted TLS connection
Atlas or another SRV deployment Use its mongodb+srv:// URI SRV-based discovery; TLS is enabled automatically
Start in a named database mongosh "mongodb://localhost:27017/qa" Database qa instead of the default test

If a port is omitted for a host-based connection, mongosh uses 27017. A URI is usually easiest to save in deployment documentation because it keeps the host, port, database, and options together; command-line options can be clearer when you are changing one value for a single session.

Connect to a non-default local port

MongoDB installations do not all use port 27017. Substitute the port on which your local server listens:

mongosh "mongodb://localhost:28015"

The equivalent option-based form is:

mongosh --port 28015

These commands differ only in how the port is expressed. If one fails, verify the configured listening port and that the server process is running; changing the shell command cannot make an unavailable listener accept connections. When troubleshooting, first try the explicit URI so the destination is unambiguous, then check whether a local firewall or service policy is preventing access.

Connect to another host

Use a resolvable DNS name or IP address for a MongoDB process on another machine. A URI example is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Sale
Smart Watch for Men Women Compatible with iPhone Samsung Android Phone 1.69 inch Full Touch Screen IP68 Waterproof Bluetooh Fitness Tracker Heart Rate/Sleep Monitor (Black)
  • 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
  • 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
  • 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
  • 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
  • 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.
mongosh "mongodb://mongodb0.example.com:28015"

The same destination can be written with separate options:

mongosh --host mongodb0.example.com --port 28015

When --port is omitted, the shell assumes port 27017:

mongosh --host mongodb0.example.com

Remote access has more failure points than a local connection. The hostname must resolve from the VPS, the selected port must be reachable through network controls, and MongoDB must be listening on an interface reachable from your source. A successful SSH session proves only that SSH is reachable; it does not prove that the MongoDB port is open.

For a replica set or another multi-host topology, use the connection URI supplied by the administrator or deployment platform. Such URIs carry the host list and topology options that a single-host command cannot express reliably. Do not replace a published multi-host URI with one member’s address unless you have confirmed that this is the intended connection method.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Authenticate with a username and password

When access control is enabled, provide the username and the database against which that username is authenticated. For example:

mongosh "mongodb://mongodb0.example.com:28015" --username alice --authenticationDatabase admin

--authenticationDatabase admin means that the credentials for alice are looked up in the admin database. It does not force your application work to occur in admin; the authentication database and the database you query can be different.

Rank #3
New Bee Guitar Cable 10ft Electric Instrument Bass AMP Cord
  • [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
  • [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
  • [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
  • [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
  • [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by

After you run the command, mongosh prompts for the password and hides the characters as you type. This interactive prompt is preferable to placing a password directly in a command line, because command history and process listings can expose literal secrets. If your operational policy requires a URI containing credentials, protect the URI as a secret and avoid storing it in shell history, tickets, or shared documentation.

If authentication fails, check all three pieces together: the exact username, the authentication database, and the host you reached. A user created in one authentication database is not automatically found in another. An otherwise correct password will still fail if the shell is pointed at a different deployment or if the server expects a different authentication mechanism.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use TLS when the deployment requires encryption

Add the --tls option to an option-based connection:

mongosh --host mongodb0.example.com --port 28015 --tls

With a URI, append the TLS query option:

mongosh "mongodb://mongodb0.example.com:28015/?tls=true"

A mongodb+srv:// URI automatically enables TLS. Use the complete SRV URI provided for the deployment rather than converting it to a guessed host-and-port string; SRV records can identify the appropriate hosts and connection settings.

TLS changes transport security, not authorization. You may still need --username, --authenticationDatabase, and the password prompt. Conversely, supplying credentials does not turn an unencrypted connection into a TLS connection. If a TLS handshake fails, confirm that the deployment requires TLS, that the hostname in the URI matches the certificate identity, and that any required trust or client-certificate settings supplied by the administrator are present.

Open a particular database immediately

Put the database name after the host and port in the URI:

Rank #4
BSIMB 15.6" Digital Family Calendar & Chore Chart, No Subscription Fees
  • Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
  • Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
  • All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
  • Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
  • Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.
mongosh "mongodb://localhost:27017/qa"

This starts the session with qa as the selected database. If no database appears in the URI, the shell uses test by default. Selecting a database changes the context for commands that operate on the current database; it does not create a new database merely by naming it in the URI.

You can combine a database path with authentication and TLS parameters in the same URI. Keep the path before the query portion, then add options such as ?tls=true; credentials supplied through command options still require the appropriate authentication database.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Confirm which deployment you reached

After the prompt appears, run:

db.getMongo()

This reports the active MongoDB connection object, allowing you to verify the host and connection details rather than relying on memory about which VPS or port your terminal is using. Make this check especially important when several environments share similar names, when an SSH tunnel or proxy is involved, or when you connected with a long URI containing multiple options.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If the reported destination is not the one you intended, leave the session, correct the URI or options, and reconnect. Do not run administrative or data-changing commands until the destination is confirmed.

Troubleshoot the most common connection failures

“mongosh: command not found”

The shell is not installed or is not on the current user’s PATH. Install mongosh using the package source appropriate for the VPS distribution, then verify with mongosh --version. If another user can run it but you cannot, compare their PATH and installation permissions rather than changing the MongoDB server configuration.

Connection refused on localhost

The process may be stopped, listening on a different port, or bound somewhere other than the address you selected. Test the explicit port form, such as mongosh "mongodb://localhost:28015", after confirming the server’s configured listener. A refusal is different from an authentication error: the shell has not reached a server that can ask for credentials.

Timeout or unreachable remote host

Check DNS resolution from the VPS, the host and port in the command, and network controls between the VPS and MongoDB. A remote deployment may intentionally accept connections only from an allowlist or private network. If the server is reachable only through a secure network path, use the connection method approved by its administrator instead of exposing a database port publicly.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Authentication failed

Re-run the command with the exact username and --authenticationDatabase expected by the deployment, then enter the password at the prompt. Check that you did not connect to a staging or production host with a similarly named account. A successful TCP connection does not establish that the supplied user has permission to read or modify a particular database.

TLS or certificate error

Confirm whether TLS is mandatory and that you used --tls or ?tls=true. For SRV connections, remember that TLS is enabled automatically. Certificate validation can still fail when the hostname is wrong, the server certificate is not trusted by the VPS, or the deployment requires client-side certificate settings that are missing. Obtain the exact TLS requirements from the MongoDB administrator or hosting platform rather than disabling verification as a shortcut.

You connected but are in the wrong database

Inspect the URI for a database path. No path selects test; adding /qa, for example, selects qa at startup. Authentication can still occur against admin or another authentication database, so distinguish the database in the URI from the database named by --authenticationDatabase.

Connection choices at a glance

  • Same VPS, default setup: use mongosh.
  • Same VPS, custom port: use a URI with that port or --port.
  • Different server: specify --host and the port, or use a complete URI.
  • Protected deployment: add the username and authentication database, then answer the hidden password prompt.
  • Encrypted transport: add --tls or ?tls=true; an SRV URI enables TLS automatically.
  • Specific working database: append its name to the URI path; otherwise the shell starts with test.
  • Replica set or cloud SRV topology: use the deployment’s supplied URI so discovery and topology options are preserved.

Leave the shell safely

At the mongosh prompt, any of these exits the interactive session:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • .exit
  • exit()
  • quit()
  • Press Ctrl-D
  • Press Ctrl-C twice

Exiting mongosh does not stop MongoDB. It closes your client session and returns you to the VPS shell, where you can disconnect from SSH or perform another administrative task.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.