avatarM. Ramadhan

Summary

The provided content is a comprehensive guide on installing MongoDB Shell on Windows, detailing the benefits, requirements, and step-by-step installation process.

Abstract

The article "Step-by-Step to Install MongoDB Shell on Windows" serves as an introductory guide for newcomers to MongoDB, outlining the process of installing the MongoDB Shell. It emphasizes the advantages of using the shell for direct interaction with MongoDB databases, learning MongoDB Query Language (MQL), debugging, data exploration, automation, compatibility, performance monitoring, and consistency. The guide specifies the minimum system requirements for running MongoDB Shell on Windows, including compatible operating systems, processor architecture, RAM, disk space, and network connectivity. It walks readers through downloading the shell from the official MongoDB website, running the installer, and following the installation wizard to set up the software. The article concludes with instructions on testing the installed MongoDB Shell, creating a desktop shortcut for easy access, and encourages users to leverage the shell's powerful features for efficient database management.

Opinions

  • The author suggests that MongoDB Shell is particularly beneficial for those who prefer or require command-line interaction with MongoDB databases.
  • It is implied that using MongoDB Shell can enhance understanding of MongoDB's fundamental operations and facilitate learning of MQL.
  • The article conveys that MongoDB Shell is a lightweight tool suitable for various environments and use cases, including quick data exploration and ad-hoc queries.
  • The guide promotes the use of MongoDB Shell for scripting and automation of database-related tasks, which can improve efficiency and productivity.
  • The author highlights the importance of checking the official MongoDB documentation for the latest system requirements and best practices.
  • The article encourages enabling telemetry to contribute to the improvement of the MongoDB Shell through anonymous usage data collection.

Step-by-Step to Install MongoDB Shell on Windows

An easy guide for newbies

Table of Contents

OverviewBenefitsMinimum RequirementsGuide to InstallingDownload MongoDB ShellRun the InstallerFollow the Installation WizardTest MongoDB ShellCreate ShortcutSummaryReferences

Photo by Lindsay Henwood on Unsplash

Overview

MongoDB is a popular open-source NoSQL (non-relational) database management system. It falls under the category of document-oriented databases, meaning it stores data in a semi-structured document format (usually JSON-like documents) rather than traditional rows and columns found in relational databases.

You can interact with MongoDB in two ways: ▹ MongoDB Compass ▹ MongoDB Shell

In the previous article, we installed MongoDB Community and Compass. For now, we cover installing MongoDB Shell.

Installing MongoDB Shell can be beneficial if you work directly with the MongoDB database through the command line interface. It allows you to interact with the database using the MongoDB Query Language (MQL) without needing a graphical user interface.

Benefits

MongoDB Shell offers several benefits for those who want to interact with MongoDB databases through the command-line interface.

Direct Interaction MongoDB Shell allows you to interact directly with the database, providing a powerful way to work with data, run queries, and perform administrative tasks without needing a graphical user interface.

Learning and Understanding Using MongoDB Shell can help you learn how MongoDB works at a fundamental level. You can observe how data is structured, execute queries, and understand how MongoDB processes your commands.

Debugging and Testing When troubleshooting issues or debugging queries, MongoDB Shell can be invaluable. You can execute queries step by step, examine query results, and identify potential problems in your data or queries.

Quick Data Exploration For quick data exploration and ad-hoc queries, MongoDB Shell can be faster than setting up and navigating through a graphical tool. You can perform actions such as finding documents, aggregating data, and modifying records directly.

Automation and Scripting MongoDB Shell allows you to write scripts in JavaScript or other supported scripting languages to automate repetitive tasks, perform batch operations, and schedule database maintenance.

Compatibility MongoDB Shell is available for various platforms, making it convenient to use across different operating systems without relying on a specific tool’s compatibility.

Flexibility With MongoDB Shell, you have fine-grained control over your interactions with the database. You can customize queries and commands based on your specific requirements.

Lightweight The shell is lightweight and does not require a graphical interface or extensive resources, making it suitable for various environments.

Security and Remote Access MongoDB Shell can securely access databases hosted remotely without graphical tools or remote desktop connections.

Performance Monitoring MongoDB Shell allows you to run administrative commands and retrieve performance-related information, helping you monitor the health and performance of your MongoDB instances.

Consistency By using the same command-line interface, you can ensure consistency in how you interact with the database across different systems and environments.

It’s important to note that while MongoDB Shell offers many benefits, it does require familiarity with command-line interfaces and some knowledge of the MongoDB Query Language (MQL).

Minimum Requirements

To run MongoDB Shell on Windows, you must ensure your system meets the following minimum requirements.

Operating System MongoDB Shell is compatible with various versions of Windows. It supports Windows 7 or later. However, checking the official MongoDB documentation or releasing notes for the latest information on supported Windows versions is always best.

Processor MongoDB Shell is not resource-intensive, so a standard modern processor should be sufficient. Any multi-core processor with 64-bit architecture should work well.

RAM MongoDB Shell itself does not require a significant amount of RAM. However, the overall system’s performance will benefit from having at least 4GB of RAM, with more being preferable for larger datasets and complex queries.

Disk Space MongoDB Shell is a relatively small package, requiring only a few hundred megabytes of disk space for installation. However, remember that the actual data storage for MongoDB databases will depend on your use case and requirements.

Network Connectivity MongoDB Shell requires network connectivity to communicate with a MongoDB server running on the same machine or a remote server. Ensure your system has an active network connection to work with remote databases.

Before installing MongoDB Shell on your Windows machine, review the official MongoDB documentation or release notes for any updates or changes to the system requirements, especially if there have been new releases or versions. Additionally, consider checking the MongoDB website for any recommended hardware configurations or best practices to optimize your MongoDB environment on Windows.

Guide to Installing

Here’s a step-by-step guide to installing MongoDB Shell on Windows.

Download MongoDB Shell

  • In the Version dropdown, select the version of MongoDB to download.
  • In the Platform dropdown, select Windows 64-bit (8.1+)(MSI).
  • In the Package dropdown, select msi.
  • Click on the Download button.

Run the Installer

  • Open the File Explorer.
  • Go to the directory where you saved the MongoDB installer (.msi file).
  • Double-click the .msi file.

Follow the Installation Wizard

The wizard steps you through the installation of MongoDB Shell.

  • Click the Next button.
  • If you want, you can change the destination folder. For example, change drive C to D.
  • Click the Next button.
  • Click the Install button.
  • Installation is in progress.
  • Click Finish to end the installation.

Test MongoDB Shell

  • Open the File Explorer and go to the folder: D:\Users\Sony\AppData\Local\Programs\mongosh
  • Double click the mongosh.exe file to start MongoDB Shell.
  • Press and type help
  • MongoDB Shell displays the following:
Please enter a MongoDB connection string (Default: mongodb://localhost/):

Current Mongosh Log ID: 64d48df1752f62b6096d1198
Connecting to:          mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.10.3
Using MongoDB:          6.0.8
Using Mongosh:          1.10.3

For mongosh info see: https://docs.mongodb.com/mongodb-shell/

------
   The server generated these startup warnings when booting
   2023-08-08T15:23:18.728+07:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
------

test> help

  Shell Help:

    use                                        Set current database
    show                                       'show databases'/'show dbs': Print a list of all available databases.
                                               'show collections'/'show tables': Print a list of all collections for current database.
                                               'show profile': Prints system.profile information.
                                               'show users': Print a list of all users for current database.
                                               'show roles': Print a list of all roles for current database.
                                               'show log <type>': log for current connection, if type is not set uses 'global'
                                               'show logs': Print all logs.

    exit                                       Quit the MongoDB shell with exit/exit()/.exit
    quit                                       Quit the MongoDB shell with quit/quit()
    Mongo                                      Create a new connection and return the Mongo object. Usage: new Mongo(URI, options [optional])
    connect                                    Create a new connection and return the Database object. Usage: connect(URI, username [optional], password [optional])
    it                                         result of the last line evaluated; use to further iterate
    version                                    Shell version
    load                                       Loads and runs a JavaScript file into the current shell environment
    enableTelemetry                            Enables collection of anonymous usage data to improve the mongosh CLI
    disableTelemetry                           Disables collection of anonymous usage data to improve the mongosh CLI
    passwordPrompt                             Prompts the user for a password
    sleep                                      Sleep for the specified number of milliseconds
    print                                      Prints the contents of an object to the output
    printjson                                  Alias for print()
    convertShardKeyToHashed                    Returns the hashed value for the input using the same hashing function as a hashed index.
    cls                                        Clears the screen like console.clear()
    isInteractive                              Returns whether the shell will enter or has entered interactive mode

  For more information on usage: https://docs.mongodb.com/manual/reference/method
test>
  • To exit MongoDB Shell, type exit.

Create Shortcut

It’s best to make a shortcut for MongoDB Shell.

  • Right-click the mongosh.exe file and select: Send to | Desktop (create shortcut)
  • To start MongoDB Shell, double-click the shortcut on the desktop.

Summary

Installing MongoDB Shell can be beneficial if you work directly with the MongoDB database through the command line interface. It allows you to interact with the database using the MongoDB Query Language (MQL) without needing a graphical user interface. Enjoy exploring the power and flexibility of MongoDB Shell for your data management needs.

Thanks for reading. I hope it’s helpful.

References

Mongodb
Mongodb Shell
Mongodb Compass
Mongodb Community
Mql
Recommended from ReadMedium