logo
icon

MongoDB

A source-available, cross-platform, document-oriented database program.

template cover
Deployed838 times
Publisheryuaanlin
Created2024-03-29
Services
service icon
Tags
Database

MongoDB is an open source NoSQL database management program. NoSQL (Not only SQL) is used as an alternative to traditional relational databases. NoSQL databases are quite useful for working with large sets of distributed data. MongoDB is a tool that can manage document-oriented information, store or retrieve information.

MongoDB is used for high-volume data storage, helping organizations store large amounts of data while still performing rapidly. Organizations also use MongoDB for its ad-hoc queries, indexing, load balancing, aggregation, server-side JavaScript execution and other features.

Environment variables

You can access the following environment variables in your other services in the same project:

  • MONGO_CONNECTION_STRING: The connection string to connect to your MongoDB.
  • MONGO_HOST: The hostname of your MongoDB.
  • MONGO_PASSWORD: The password of your MongoDB.
  • MONGO_PORT: The port of your MongoDB.
  • MONGO_URI: The connection string to connect to your MongoDB.
  • MONGO_USERNAME: The username of your MongoDB.

You can use these environment variables in your other services to connect to your MongoDB.

Connecting to your MongoDB

There are two useful tools to connect to and operate your MongoDB:

MongoDB Compass

MongoDB Compass is an interactive tool "for querying, optimizing, and analyzing your MongoDB data, and allow getting key insights, dragging and droping to build pipelines, and more".

Once you have downloaded and installed it according to the official documentation, go back to your Zeabur dashboard. Click on the Connections tab in the MongoDB service, and click the eye icon to copy the connection string.

connect-path

Paste the copied content into the URI input box:

input-to-URI

Choose Save & Connect or Connect according to your needs, and now you can start to operate MongoDB.

mongodb-compass-connect-success

mongosh

mongosh is a fully-featured JavaScript and Node.js REPL environment for interacting with MongoDB databases.

Once you have downloaded and installed it according to the documentation, go back to your Zeabur dashboard. Click on the Connections tab in the MongoDB service, and click the eye icon to copy the connection string.

connect-path

mongosh mongodb://<YOUR_CONNECT_PATH>

Replace <YOUR_CONNECT_PATH> with the connection string you just copied, and we can use the following command to test if the connection is successful:

use mongodb_test
db.mongodb_test.insertOne({content: "Hello World"})
show dbs

If successful, it should return:

mongosh-connect-success

Then we can drop the test database.

use mongodb_test
db.drop()