Creating a MongoDB data service#
This tutorial creates an Ametnes-managed MongoDB database — a private document service reached through an Ametnes network access endpoint.
Ametnes offers the MongoDB community server in two release families:
service/mongodb:8.0— MongoDB 8.0 LTSservice/mongodb:9.0— MongoDB 9.0
Every architecture tier runs a three-member replica set. There is no
single-node tier: Starter is already a highly-available three-node
deployment, with one primary and two secondaries.
Prerequisites#
- A service location (see Service Location).
Networking is automatic by default
Creating a network access resource is optional. If you do not create one, Ametnes manages network access for the location and the service attaches automatically. Create your own only if you want to control exposure (see Network Access Resources).
Connections#
The service returns three member connections:
| Connection | Default port | Role |
|---|---|---|
mongodb |
27017 |
Primary member |
secondary |
27018 |
Secondary member |
tertiary |
27019 |
Secondary member |
The control plane may allocate different external ports when the defaults are
already in use on the endpoint. Always use the host and port
returned in the service's connections array rather than assuming the
defaults.
All three hosts advertise the same replica set name, rs0. Clients should use
all three connections and let the MongoDB driver discover the current primary;
the primary role can move between members.
Create the MongoDB service#
- Navigate to Services and click New Service.
- Enter Name (for example
MongoDBService). - Select Kind: MongoDB 8.0 Service or MongoDB 9.0 Service.
- Select the Location: your data service location. Leave Network unset to let Ametnes manage it.
- Select Setup Architecture:
- Starter for evaluation and small workloads (3 nodes, 1 CPU / 2Gi per node, 10Gi per node).
- Small and above for larger production workloads.
- Set Admin User (default
root) and Admin Password. A password is generated when omitted. - Click Create Service and wait for status
READY.
Change kind to service/mongodb:9.0 to provision MongoDB 9.0. The
architecture controls CPU, memory, replica count and per-node storage;
every architecture remains a three-member replica set.
Connect#
Use the three MongoDB member connections returned by the service. The
connection string uses the replica set name, rs0, and authenticates against
the admin database:
mongodb://root:<password>@<mongodb-host>:<mongodb-port>,<secondary-host>:<secondary-port>,<tertiary-host>:<tertiary-port>/?replicaSet=rs0&authSource=admin&tls=true&retryWrites=true&w=majority
With mongosh:
mongosh "mongodb://root:<password>@<host-1>:<port-1>,<host-2>:<port-2>,<host-3>:<port-3>/?replicaSet=rs0&authSource=admin&tls=true"
The admin user defaults to root. Use the password from the service's secret,
or the password you supplied at creation time.
Architectures#
Every architecture is a three-node replica set. Requests are half of the limits, and storage is per node, so the total raw storage is three times the listed per-node size.
| Architecture | Nodes | CPU / memory per node | Storage per node | ACU |
|---|---|---|---|---|
| Starter | 3 | 1 CPU / 2Gi | 10Gi | 6 |
| Small | 3 | 2 CPU / 4Gi | 25Gi | 12 |
| Basic | 3 | 2 CPU / 4Gi | 50Gi | 12 |
| Medium | 3 | 4 CPU / 8Gi | 100Gi | 24 |
| Large | 3 | 8 CPU / 16Gi | 250Gi | 48 |
| XLarge | 3 | 16 CPU / 32Gi | 500Gi | 96 |
| 2XLarge | 3 | 24 CPU / 64Gi | 1000Gi | 192 |
| 3XLarge | 3 | 32 CPU / 96Gi | 2000Gi | 288 |
| 4XLarge | 3 | 48 CPU / 128Gi | 4000Gi | 384 |
Starter is highly available
Unlike some other Ametnes data services, the MongoDB Starter tier is not
a single node. It runs three members so the replica set can elect a new
primary if a node fails.
Scale#
Use Modify Resource in the console to move to a larger architecture. MongoDB tiers share the same three-member topology, so a tier change does not change the replica-set layout: the existing members are resized and storage is increased per node.
To use a different MongoDB major version, provision the target version service
(for example service/mongodb:9.0) and migrate the data using your normal
MongoDB migration or dump/restore process. Major-version changes are a new
service rather than an in-place tier change.
Create a database and application user#
Connect with mongosh, then create a database, collection and application
user:
db.getSiblingDB("sales").createCollection("orders")
db.getSiblingDB("admin").createUser({
user: "app",
pwd: "<application-password>",
roles: [{ role: "readWrite", db: "sales" }]
})
Application connections should use the application user rather than the admin user.
Next#
- Service Location — choose where the service runs.
- Network Access Resources — control how the service is exposed.
- Resource Reference — resource kinds, capacities and connection data.