Efficiently managing exponentially growing data is a significant challenge for every growing business. This requires a scalable, flexible, and reliable Database Management solution like MongoDB. It is an Open-source Document Oriented Database Management system that can scale easily as your business grows.
To effortlessly manage MongoDB Databases, you can use Mongo Express. It is an effective Web-based Management Tool for administering MongoDB Databases interactively. Using simple Add, Delete or Modify buttons, you can perform the basic MongoDB operations.
In this article, you will learn how to easily install & run Mongo Express for managing your MongoDB Databases.
What is MongoDB?
MongoDB is a NoSQL Open-source Document Oriented Database developed for storing and processing high volumes of data. Compared to the conventional relational databases, MongoDB makes use of collections and documents instead of tables consisting of rows and columns. The Collections consist of several documents and documents containing the basic units of data in terms of key and value pairs.
Introduced in February 2009, the MongoDB database is designed, maintained, and managed by MongoDB.Inc under SSPL(Server Side Public License). Organizations such as Facebook, Nokia, eBay, Adobe, Google, etc. prefer it for efficiently handling and storing their exponentially growing data. It offers complete support for programming languages such as C, C++, C#, Go, Java, Node.js, Perl, PHP, Python, Motor, Ruby, Scala, Swift, and Mongoid.
Key Features of MongoDB?
With constant efforts from the online community, MongoDB has evolved over the years. Some of its eye-catching features are:
- High Data Availability & Stability: MongoDB’s Replication feature provides multiple servers for disaster recovery and backup. Since several servers store the same data or shards of data, MongoDB provides greater data availability & stability. This ensures all-time data access and security in case of server crashes, service interruptions, or even good old hardware failure.
- Accelerated Analytics: You may need to consider thousands to millions of variables while running Ad-hoc queries. MongoDB indexes BSON documents and utilizes the MongoDB Query Language (MQL) that allows you to update Ad-hoc queries in real-time. MongoDB provides complete support for field queries, range queries, and regular expression searches along with user-defined functions.
- Indexing: With a wide range of indices and features with language-specific sort orders that support complex access patterns to datasets, MongoDB provides optimal performance for every query. For the real-time ever-evolving query patterns and application requirements, MongoDB also provisions On-demand Indices Creation.
- Horizontal Scalability: With the help of Sharding, MongoDB provides horizontal scalability by distributing data on multiple servers using the Shard Key. Each shard in every MongoDB Cluster stores parts of the data, thereby acting as a separate database. This collection of comprehensive databases allows efficient handling of growing volumes of data with zero downtime. The complete Sharding Ecosystem is maintained and managed by Mongos that directs queries to the correct shard based on the Shard Key.
- Load Balancing: Real-time Replication and Sharding contribute towards large-scale Load Balancing. Ensuring top-notch Concurrency Controls and Locking Protocols, MongoDB can effectively handle multiple concurrent read and write requests for the same data.
- Aggregation: Similar to the SQL Group By clause, MongoDB can easily batch process data and present a single result even after executing several other operations on the group data. MongoDB’s Aggregation framework consists of 3 types of aggregations i.e. Aggregation Pipeline, Map-Reduce Function, and Single-Purpose Aggregation methods.
What is Mongo Express?
Mongo Express is an interactive lightweight Web-Based Administrative Tool to effectively manage MongoDB Databases. Written with Node.js, Express, and Bootstrap3, Mongo Express can be used to simplify several MongoDB Admin tasks. Using Mongo Express, you can add, delete or modify databases, collections, and documents. With GridFS support, Mongo Express allows you to easily handle and process incredibly large files. It also offers complete support for BSON Data Types in documents, Custom CA and CA validation disabling & Replica Sets. Since it is also based on Bootstrap 3, Mongo Express is Mobile responsive.
For a fast collection view, Mongo Express provides Async On-demand Loading of big document properties (>100KB default). You can also have a bird’s eye view of your data as nested and large objects are collapsible. Mongo Express also provides an inline preview of your audio/video/image assets in the collection view.
Mongo Express BSON Data Types
MongoDB Express supports the following BSON Data Types:
- Javascript Types: This includes Strings, numbers, lists, booleans, null, etc where the numbers in Javascript are 64-bit floating points.
- ObjectID/ObjectID(id): ObjectID creates a new Object ID type where as the ObjectID(id) statement uses the Object ID with the given 24-digit hexadecimal string.
- ISODate: This is used to create an ISODate object with the current time. You can also provide a timestamp argument to create an ISODate object with a specified time.
- DBRef/Dbref: For this, you can use DBRef(collection, objectID) statement for linking documents easily.
- Timestamp: You can use Timestamp(time, ordinal) to create a new Timestamp object with the specified time.
- Code: This can be a native Javascript function or maybe even a string.
Apart from these Mongo Express document editor/viewer also supports MinKey, MaxKey & Symbol.
Prerequisites
- MongoDB should be up & running.
- Node.js v4 or higher should be installed.
How to set up Mongo Express?
Before setting up Mongo Express, it is to be noted that Mongo Express comes with a config-default.js file that primarily supports basic authentication. It only includes the base64 encoded payload of a username:password combination. Hence, you may observe several warnings on the console. For better data security, it is recommended to restrict access with strong credentials and deploy perimeter access controls. You can also run Mongo Express privately for development purposes by copying config.default.js to config.js and editing the default property to fit your local environment.
To run the development build, execute the following command:
npm run start-dev
To set up Mongo Express on your system, follow these simple steps:
Step 1: Installing Mongo Express
- Step 1: To install Mongo Express on your system execute the following command:
npm install -g mongo-express
- Step 2: For installing a Non-global copy, run the following command:
npm install mongo-express
Step 2: Configuring Mongo Express
- Step 1: After executing the npm install command, you can now copy YOUR_PATH/node_modules/mongo-express/config.default.js into a new file called YOUR_PATH/node_modules/mongo-express/config.js. The keyword “YOUR_PATH” identifies the current OS user and system configuration.
- Step 2: Now, provide all your MongoDB connection details and any other options you want to modify in config.js.
Step 3: Running Mongo Express
- Step 1: Execute the following command to run Mongo Express:
cd YOUR_PATH/node_modules/mongo-express/ && node app.js
You can also run Mongo Express directly if you have it globally:
mongo-express --url mongodb://127.0.0.1:27017
- Step 2: For running Mongo Express as an administrator, use the command given below:
mongo-express --admin --url mongodb://127.0.0.1:27017
For any assistance on the Mongo Express configuration options, use the following command:
mongo-express --help
Mongo Express with Docker
To use MongoDB with Docker, ensure that a MongoDB container is running on a Docker network (–network some-network below) with –name or –network-alias set to mongo. You can also set the connection string ME_CONFIG_MONGODB_URL to the right connection for your MongoDB container on your Docker network. You run the Docker image via the following 2 methods:
$ docker run -it --rm -p 8081:8081 --network some-network mongo-express
- Method 2: You can also build an image from the project directory & then run the image. To do that, execute the following commands:
$ docker build -t mongo-express
$ docker run -it --rm -p 8081:8081 --network some-network mongo-express
You can also change the container’s configuration by using the following environment variables:
Name | Default | Description
----------------------------------|-----------------|------------
`ME_CONFIG_MONGODB_URL` | `mongodb://admin:pass@localhost:27017/db?ssl=false`
`ME_CONFIG_MONGODB_ENABLE_ADMIN` | `false` | Enable administrator access. Send strings: `"true"` or `"false"`.
`ME_CONFIG_MONGODB_AUTH_DATABASE` | `db` | Database name (only needed if `ENABLE_ADMIN` is `"false"`).
`ME_CONFIG_MONGODB_AUTH_USERNAME` | `admin` | Database username (only needed if `ENABLE_ADMIN` is `"false"`).
`ME_CONFIG_MONGODB_AUTH_PASSWORD` | `pass` | Database password (only needed if `ENABLE_ADMIN` is `"false"`).
`ME_CONFIG_SITE_BASEURL` | `/` | Set the express baseUrl to ease mounting at a subdirectory. Remember to include a leading and trailing slash.
`ME_CONFIG_SITE_COOKIESECRET` | `cookiesecret` | String used by [cookie-parser middleware](https://www.npmjs.com/package/cookie-parser) to sign cookies.
`ME_CONFIG_SITE_SESSIONSECRET` | `sessionsecret` | String used to sign the session ID cookie by [express-session middleware](https://www.npmjs.com/package/express-session).
`ME_CONFIG_BASICAUTH_USERNAME` | `` | mongo-express web login name. Sending an empty string will disable basic authentication.
`ME_CONFIG_BASICAUTH_PASSWORD` | `` | mongo-express web login password.
`ME_CONFIG_REQUEST_SIZE` | `100kb` | Used to configure maximum mongo update payload size. CRUD operations above this size will fail due to restrictions in [body-parser](https://www.npmjs.com/package/body-parser).
`ME_CONFIG_OPTIONS_EDITORTHEME` | `rubyblue` | Web editor color theme, [more here](http://codemirror.net/demo/theme.html).
`ME_CONFIG_OPTIONS_READONLY` | `false` | if readOnly is true, components of writing are not visible.
`ME_CONFIG_OPTIONS_NO_DELETE` | `false` | if noDelete is true, components of deleting are not visible.
`ME_CONFIG_SITE_SSL_ENABLED` | `false` | Enable SSL.
`ME_CONFIG_MONGODB_SSLVALIDATE` | `true` | Validate mongod server certificate against CA
`ME_CONFIG_SITE_SSL_CRT_PATH` | ` ` | SSL certificate file.
`ME_CONFIG_SITE_SSL_KEY_PATH` | ` ` | SSL key file.
`ME_CONFIG_SITE_GRIDFS_ENABLED` | `false` | Enable gridFS to manage uploaded files.
`VCAP_APP_HOST` | `localhost` | address that mongo-express will listen on for incoming connections.
`VCAP_APP_PORT` | `8081` | port that mongo-express will run on.
`ME_CONFIG_MONGODB_CA_FILE` | `` | CA certificate File
`ME_CONFIG_BASICAUTH_USERNAME_FILE` | `` | File version of ME_CONFIG_BASICAUTH_USERNAME
`ME_CONFIG_BASICAUTH_PASSWORD_FILE` | `` | File version of ME_CONFIG_BASICAUTH_PASSWORD
`ME_CONFIG_MONGODB_ADMINUSERNAME_FILE` | `` | File version of ME_CONFIG_MONGODB_ADMINUSERNAME
`ME_CONFIG_MONGODB_ADMINPASSWORD_FILE` | `` | File version of ME_CONFIG_MONGODB_ADMINPASSWORD
`ME_CONFIG_MONGODB_AUTH_USERNAME_FILE` | `` | File version of ME_CONFIG_MONGODB_AUTH_USERNAME
`ME_CONFIG_MONGODB_AUTH_PASSWORD_FILE` | `` | File version of ME_CONFIG_MONGODB_AUTH_PASSWORD
The below example connects to a container name typical of docker-compose, modifies the editor’s color theme, and deactivates the basic authentication.
docker run -it --rm
--name mongo-express
--network web_default
-p 8081:8081
-e ME_CONFIG_OPTIONS_EDITORTHEME="ambiance"
-e ME_CONFIG_BASICAUTH_USERNAME=""
-e ME_CONFIG_MONGODB_URL="mongodb://mongo:27017"
mongo-express
For both of the above methods, the default port exposed from the container is 8081. You can also specify a port of your choice in the configuration settings. To start working with Mongo Express you can now visit http://localhost:8081 or http://host-ip:8081 in your browser.
Conclusion
In this article, you have learned how to install & run Mongo Express on your browser. You can now start using it to manage your MongoDB Databases. Mongo Express provides an interactive interface that allows you to add, delete or modify databases, collections, and documents.
Mongo Express supports several BSON Data Types except for the Binary BSON Data Type which has not been tested yet. You can connect and authenticate to individual databases and simplify your mundane MongoDB Admin tasks.
Tell us about your experience of setting up Mongo Express! Share your thoughts with us in the comments section below.
Sanchit Agarwal is an Engineer turned Data Analyst with a passion for data, software architecture and AI. He leverages his diverse technical background and 2+ years of experience to write content. He has penned over 200 articles on data integration and infrastructures, driven by a desire to empower data practitioners with practical solutions for their everyday challenges.