MongoDB Server

type access

  • Operating System:

  • Terminal:

  • Shell:

  • Editor:

  • Package Manager:

  • Programming Language:

  • Database:

  • Extension:

type access

  • Operating System:

  • Terminal:

  • Shell:

  • Editor:

  • Package Manager:

  • Programming Language:

  • Database:

  • Extension:

MongoDB is a NoSQL database that stores data in flexible, JSON-like documents. It is designed for scalability and developer agility. In contrast to relational databases, it supports dynamic schemas, which simplifies and accelerates data integration.

Initialization

For guidance on utilizing Initialization parameter, consult the Use Cases section of the documentation.

Create a New Server

To run the application, the Database directory parameter must be specified. This parameter defines the MongoDB database folder to be imported from a UCloud workspace. If the designated folder is empty, a new database instance is initialized.

Authentication can be enabled by supplying values for the Admin user and Admin password parameters. Additional MongoDB options may be configured by providing a custom Configuration file.

Note

By default, the database listens on port 27017. An alternative port can be specified using the corresponding optional parameter.

Schedule Regular Backups

The application includes an option to schedule hourly backups. Backup folders are timestamped and stored at path/to/database/directory/database_dump.

Database dumps can also be created manually using the mongodump utility from the terminal interface. This utility produces binary exports of the MongoDB instance contents. For example:

$ mongodump --gzip --out <database_dump> --db <database_name>

If the --db option is not specified, all databases on the server are included in the dump.

When authentication is required, the command should also include the --username, --password, and --authenticationDatabase flags. The default authentication database is admin.

Restore a Database Dump

A database can be restored from the command line using the mongorestore utility. For example:

$ mongorestore --host=localhost --port=<port> <database_dump> --gzip --username=<user> --password=<password> --authenticationDatabase=admin

If authentication is not required, the command is:

$ mongorestore --host=localhost --port=<port> <database_dump> --gzip

In both cases, <port> must be replaced with the port number on which the MongoDB server is running. The default port is 27017.

Backups must be created using the mongodump utility.

Connect to the Server

The MongoDB console can be accessed directly through the integrated terminal interface, for example:

$ mongosh -u <username> -p <password>

This assumes that the database server was started with authentication enabled. Alternatively, a connection to the MongoDB server may be established using an external client tool.

When the client tool is part of another interactive application available on UCloud, a direct connection to the MongoDB server can be established as described here.

If, on the other hand, the MongoDB client is a standalone third-party application running outside UCloud, it is necessary to assign a static IP address to the MongoDB server.

For servers launched with a custom configuration file, the following entries must be included:

net:
  bindIp: 0.0.0.0
  port: 27017

This configuration enables connections from all IP interfaces. Setting the bindIp option to 0.0.0.0 ensures that MongoDB listens for connections from any address.

Note

The static IP address must use the same port in order to establish a connection.