iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
Need a server to try this on? Antihost offers Linux VPS plans with NVMe storage, full root access and a 14-day free trial.
SSH into the Linux VPS, make sure the current MongoDB shell command mongosh is installed, and run mongosh. With MongoDB listening on the local default endpoint, that opens a shell connected to localhost:27017. The equivalent explicit command is mongosh "mongodb://localhost:27017".
Use a connection string or command-line options when the server uses another port, a different hostname, authentication, TLS, a specific database, Atlas, or a replica set. This guide shows each form, how to verify the session, and how to diagnose the most common connection mistakes.
Recommended Free Tools
What you need before connecting
The connection procedures below assume that you already have an SSH session on the VPS and that mongosh is installed. mongosh is the current MongoDB shell command used for these connection flows; older instructions that refer only to the legacy mongo executable do not describe the command shown here.
Access to the VPS
Connect to the server with your normal SSH client and account. Run the shell command from that SSH session, not from your own computer, when MongoDB is running on the VPS itself. The shell process then runs on the same Linux host as the database service.
#1 Best Overall
- Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
- With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
- Wide Application:Upgraded attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
- Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
- Warranty & Support: Our Electric air duster comes with 5 years warranty and 24/7 customer service. During this period, if you have any questions,pls kindly feel free to contact us.
The shell executable
Confirm that the command is available before troubleshooting MongoDB networking. A missing command means the client is not installed or is not on the account’s executable path; it is different from a database authentication failure or an unavailable server.
mongosh --version
The exact version output is not required for the connection syntax in this guide. If the command is not found, install the MongoDB Shell using the instructions appropriate for your Linux distribution and then repeat the version check.
The endpoint details
Decide which deployment you intend to reach before choosing a command. The endpoint determines the hostname, port, security options, and (optionally) the database selected when the shell starts.
| Situation | Connection target | Typical form |
|---|---|---|
| MongoDB on this VPS, default port | localhost:27017 |
mongosh |
| MongoDB on this VPS, custom port | localhost:28015 in this example |
mongosh --port 28015 |
| Named host, custom port | mongodb0.example.com:28015 in this example |
mongosh --host mongodb0.example.com --port 28015 |
| Authenticated deployment | Host and port plus a user and authentication database | mongosh "mongodb://mongodb0.example.com:28015" --username alice --authenticationDatabase admin |
| TLS connection | Any compatible endpoint with TLS enabled | mongosh --tls or a URI containing ?tls=true |
The hostnames and ports in the examples are illustrative connection values. Replace them with the endpoint configured for your deployment.
Open a local MongoDB shell with the default settings
When MongoDB is running on the VPS and accepts its default local endpoint, the shortest documented command is:
mongosh
That command connects to localhost on port 27017. MongoDB documents it as equivalent to:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
mongosh "mongodb://localhost:27017"
The unadorned command is convenient for routine administration because it leaves the host, port, and database at their defaults. The URI form is useful when you want the endpoint to be visible in a script, runbook, or copied command.
What you should see
After a successful connection, mongosh displays its startup information and presents an interactive prompt. The prompt means the client has established a session; it does not by itself tell you which application database you meant to use. Confirm the actual connection with db.getMongo() before running an operation against a production deployment.
Use a non-default port
If MongoDB listens on another port, specify that port explicitly. The following examples use port 28015:
Rank #2
- Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
- Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
- Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
- Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
- Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth
mongosh "mongodb://localhost:28015"
MongoDB’s shell also accepts the port as an option:
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchesmongosh --port 28015
These forms describe the same local-host destination. The URI is generally easier to extend with a database name or additional connection options; the option form is easy to read when only the port differs from the default.
Do not silently rely on 27017
If you omit --port while connecting to a host, mongosh uses port 27017. A service configured on 28015, or any other custom port, will not be reached by a command that leaves the port unspecified. Make the non-default port part of the command every time.
Connect to another host
Use a hostname or IP address when the MongoDB deployment is not on the VPS where you launched the shell. For a named host and custom port, either of these commands is valid:
mongosh "mongodb://mongodb0.example.com:28015"
mongosh --host mongodb0.example.com --port 28015
If the remote service uses its default port, you can omit the port and let mongosh use 27017:
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →mongosh --host mongodb0.example.com
Alternatively, put the host alone in a URI:
mongosh "mongodb://mongodb0.example.com"
Use the URI that matches the endpoint you were given. A correct hostname with the wrong port is still a failed connection, and a correct port on the wrong host reaches a different service or no service at all.
Single host versus service URI
A URI such as mongodb://hostname:port identifies a host and port directly. A mongodb+srv:// URI represents a service-discovery form commonly used by hosted MongoDB deployments. When you use mongodb+srv://, TLS is enabled automatically, so do not treat it as an unencrypted equivalent of a basic mongodb:// URI.
Authenticate with a username and password
When access control is enabled, provide the username and the database against which that user’s credentials are authenticated. This example authenticates user alice against the admin database while connecting to a host on port 28015:
mongosh "mongodb://mongodb0.example.com:28015" --username alice --authenticationDatabase admin
mongosh prompts for the password interactively and hides the characters as you type. This is preferable to placing a password directly in a command line that may be saved in shell history or exposed while processes are inspected.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchRank #3
- 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
- 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
- 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
- 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
- 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.
Authentication database is not necessarily the working database
The --authenticationDatabase value tells MongoDB where the user’s credentials are stored. It does not select the database in which you intend to work. You can authenticate against admin and then start in another database by adding that database to the URI:
mongosh "mongodb://mongodb0.example.com:28015/qa" --username alice --authenticationDatabase admin
Keep those two concepts separate: the authentication database validates the account, while the path after the host and port selects the initial working database.
Why an interactive password prompt matters
- The password is not visible while it is entered.
- The secret is not included in the command text you copy and paste.
- You reduce the chance that shell history records the credential.
If the prompt rejects the password, verify the username, authentication database, and endpoint together. A valid account on one MongoDB deployment will not authenticate against a different host merely because the username has the same spelling.
Enable TLS when the deployment requires encrypted transport
Add the --tls option when the server requires TLS:
mongosh "mongodb://mongodb0.example.com:28015" --tls
You can express the same requirement in the URI with the tls=true query option:
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →mongosh "mongodb://mongodb0.example.com:28015/?tls=true"
Use one clear form that matches the connection details supplied for your deployment. TLS is a transport setting; it does not replace username/password authentication when access control is enabled. A connection can require both TLS and credentials:
mongosh "mongodb://mongodb0.example.com:28015/?tls=true" --username alice --authenticationDatabase admin
For a service-discovery URI beginning with mongodb+srv://, TLS is enabled automatically. Do not remove that behavior by changing the URI scheme without confirming that the deployment supports the replacement form.
TLS troubleshooting choices
If a deployment expects TLS and the client is started without it, the connection can fail before authentication is attempted. Conversely, adding TLS to a server that is configured for plain connections can also prevent a session. Confirm whether the endpoint requires TLS and then apply --tls or ?tls=true consistently with the endpoint’s documented settings.
Start in a particular database
Append a database name to the MongoDB URI when the shell should open in a specific database. This command starts in the qa database:
mongosh "mongodb://localhost:27017/qa"
If no database is specified in the URI, the default database is test. That default affects the initial shell context; it does not change which MongoDB server you connect to.
Rank #4
- 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
- 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
- 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
- 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
- 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.
Combine database selection with other options
A database path can be combined with a remote endpoint, authentication, and TLS. For example:
mongosh "mongodb://mongodb0.example.com:28015/qa?tls=true" --username alice --authenticationDatabase admin
Read the command from left to right: the URI selects the host, port, starting database, and TLS setting; the options provide the username and the database used to authenticate that username.
Free tools Windows power users keep installed
One-click scans. No signup required.
Verify the active connection
Once the prompt appears, run:
db.getMongo()
This verifies which MongoDB connection the current shell is using. It is a useful check after switching between local and remote hosts, changing ports, or testing a TLS URI. Run it before administrative work when the destination matters, especially if you have several shell sessions open.
A practical verification sequence
- Connect with the command that matches the host and port.
- Complete the password prompt if access control is enabled.
- Run
db.getMongo()and inspect the connection target shown by the shell. - Confirm that the starting database in your prompt or commands is the one you intended; a URI without a database starts in
test. - Only then run queries or administrative operations.
This sequence separates endpoint mistakes from database-context mistakes. Reaching the right server while starting in the wrong database can still produce confusing results.
Choose the right command form
The following matrix maps common requirements to a command pattern. Replace example names with your actual values.
| Requirement | Command pattern | Important detail |
|---|---|---|
| Local deployment, default port | mongosh |
Connects to localhost:27017. |
| Local deployment, custom port | mongosh --port 28015 |
Do not omit the custom port. |
| Remote host, custom port | mongosh --host mongodb0.example.com --port 28015 |
Both host and port identify the endpoint. |
| Remote host as a URI | mongosh "mongodb://mongodb0.example.com:28015" |
Convenient for adding a database or URI option. |
| Username with prompted password | mongosh "mongodb://host:port" --username alice --authenticationDatabase admin |
Password is requested interactively. |
| TLS on a standard URI | mongosh "mongodb://host:port/?tls=true" |
The URI enables TLS. |
| TLS with an option | mongosh "mongodb://host:port" --tls |
The command-line option enables TLS. |
| Specific starting database | mongosh "mongodb://localhost:27017/qa" |
Starts in qa instead of the default test. |
| Atlas or another service-discovery URI | mongosh "mongodb+srv://..." |
The mongodb+srv:// form automatically enables TLS. |
Leave the MongoDB shell safely
At the mongosh prompt, any of these methods exits the shell:
- Enter
.exit. - Enter
exit(). - Enter
quit(). - Press Ctrl-D.
- Press Ctrl-C twice.
These commands leave the MongoDB client and return you to the Linux shell. They do not shut down the MongoDB server.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Troubleshoot a failed connection
Diagnose failures in the order the connection is established: client command, endpoint, transport security, authentication, and database context.
“Command not found” or an unavailable executable
Run mongosh --version. If Linux cannot find the command, the shell is not installed or is not on the current user’s executable path. Resolve that client-side issue before changing host, port, or credentials.
Best Value
- 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
- 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
- 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
- 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
- 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.
The shell connects to the wrong place
Run db.getMongo() after connecting. Compare the displayed target with the intended hostname and port. Check for a missing --port, because an omitted port defaults to 27017, and check that a copied URI does not contain a stale hostname.
The endpoint is not reachable
Confirm that the MongoDB deployment is actually the service you intend to reach and that the host and port are correct. A local command such as mongosh targets localhost; it will not reach a separate machine. A remote command must name the remote host, and a custom-port deployment must include its custom port.
Authentication fails
Use the username expected by the deployment and specify the database where that account is authenticated with --authenticationDatabase. Let mongosh prompt for the password rather than embedding it in the command. If the same credentials work nowhere, recheck the selected host and port before assuming the account is invalid.
TLS negotiation fails
Match the transport option to the endpoint. Add --tls or ?tls=true when TLS is required. Remember that mongodb+srv:// enables TLS automatically. If a plain endpoint is being tested, remove an accidentally added TLS option and retry only when the deployment’s connection requirements permit it.
The shell starts in an unexpected database
Inspect the URI path. A URI ending at the host and port does not name a working database, so mongosh starts in test. Add /qa, /production, or the intended database name to the URI; keep the authentication database option separate if credentials are stored in admin.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Operational habits for VPS administrators
Make the destination explicit for high-impact work
The short command mongosh is appropriate when you intentionally administer the local default deployment. For destructive, production, or incident-response work, use an explicit URI containing the hostname, port, and intended database so the destination is visible in the terminal and in your runbook.
Keep secrets out of copied commands
Use --username and let the interactive prompt request the password. Avoid placing credentials directly in a URI that may be saved in shell history, pasted into a ticket, or retained in a script. The connection syntax remains useful without exposing the secret.
Record the connection assumptions
Document whether the deployment is local or remote, which port it uses, whether TLS is mandatory, which authentication database stores the account, and which application database should be selected at startup. Those details determine the command; leaving one out encourages an accidental fallback to localhost, port 27017, or the test database.
Command reference
Keep this compact reference available when you already know the deployment details:
Recommended Free Tools
# Local MongoDB, default endpoint
mongosh
# Equivalent explicit local URI
mongosh "mongodb://localhost:27017"
# Local custom port
mongosh "mongodb://localhost:28015"
mongosh --port 28015
# Remote host and custom port
mongosh "mongodb://mongodb0.example.com:28015"
mongosh --host mongodb0.example.com --port 28015
# Username; mongosh prompts for the password
mongosh "mongodb://mongodb0.example.com:28015" --username alice --authenticationDatabase admin
# TLS with an option
mongosh "mongodb://mongodb0.example.com:28015" --tls
# TLS in the URI
mongosh "mongodb://mongodb0.example.com:28015/?tls=true"
# Start in a named database
mongosh "mongodb://localhost:27017/qa"
# Verify the active connection after startup
db.getMongo()
# Exit from the shell
.exit
exit()
quit()
Use only the lines that match your deployment. The essential decisions are locality, port, authentication, TLS, topology or URI scheme, and starting database. Once the shell is open, db.getMongo() confirms the connection before you proceed.
Quick Recap
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.

