MongoDB
Managed MongoDB with replica sets, automated backups, point-in-time recovery, and private cluster networking.
Powered by DocumentDB
Creating a MongoDB instance
From the dashboard, click New service → Database → MongoDB. Choose MongoDB 7.x, a storage size (1 GB to 500 GB), and a plan. StackBlaze provisions a StatefulSet and initializes the replica set automatically.
Attach MongoDB to your service from the Environment tab. StackBlaze injects MONGODB_URL automatically.
Connection strings
Internal (recommended)
mongodb://user:password@[service-name].internal:27017/dbname
Replica set connection (Pro+)
On Pro and Enterprise plans, MongoDB runs as a 3-node replica set. Use the replica set connection string to enable automatic failover and read preference configuration.
mongodb://user:password@[service-name]-0.internal:27017,[service-name]-1.internal:27017,[service-name]-2.internal:27017/dbname?replicaSet=rs0&authSource=admin
External (for Compass / mongosh)
Use the external connection string for MongoDB Compass or mongosh from your local machine. Find it in Settings → Connection.
mongosh "mongodb+srv://user:password@cluster.stackblaze.cloud/dbname"
Tip
mongodb+srv URI format uses DNS SRV records and automatically discovers all replica set members. Prefer it over manually listing hostnames when connecting external tools.Replica sets
| Plan | Topology | Failover |
|---|---|---|
| Free | Single node (no replica set) | None |
| Starter | Single node (no replica set) | None |
| Pro | 3-node replica set | Automatic (<30s) |
| Enterprise | 3-node replica set + hidden secondary | Automatic (<30s) |
With a 3-node replica set, MongoDB automatically elects a new primary if the current primary becomes unavailable. Your application should use the replica set connection string and enable retryable writes for seamless failover.
import mongoose from 'mongoose'
await mongoose.connect(process.env.MONGODB_URL, {
retryWrites: true,
w: 'majority',
readPreference: 'primaryPreferred',
})Automated backups
All plans include daily automated snapshots using mongodump for Free/Starter and filesystem-level snapshots for Pro/Enterprise. Backups are encrypted with AES-256 and stored in a separate availability zone.
Point-in-time recovery (PITR)
Pro and Enterprise plans support PITR via continuous oplog tailing. StackBlaze ships oplog entries to object storage, enabling recovery to any point within the retention window.
| Plan | PITR | Retention window |
|---|---|---|
| Free | No | - |
| Starter | No | 3 days (snapshots only) |
| Pro | Yes | 7 days |
| Enterprise | Yes | 30 days |
Indexes
Create indexes in your application startup code or migration scripts. For production deployments, always create indexes with { background: true } (MongoDB < 4.2) or as a rolling build to avoid blocking reads and writes on large collections.
// In your model definition
const userSchema = new mongoose.Schema({
email: { type: String, unique: true, index: true },
createdAt: { type: Date, index: true },
'profile.city': { type: String },
})
// Compound index
userSchema.index({ 'profile.city': 1, createdAt: -1 })
// Text search index
userSchema.index({ name: 'text', bio: 'text' })Connecting with common ODMs
Mongoose
import mongoose from 'mongoose'
if (mongoose.connection.readyState === 0) {
await mongoose.connect(process.env.MONGODB_URL!, {
serverSelectionTimeoutMS: 5000,
socketTimeoutMS: 45000,
})
}Prisma (MongoDB provider)
datasource db {
provider = "mongodb"
url = env("MONGODB_URL")
}
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
email String @unique
name String
}Motor (Python async)
from motor.motor_asyncio import AsyncIOMotorClient import os client = AsyncIOMotorClient(os.environ["MONGODB_URL"]) db = client.get_default_database()
Under the hood
rs.initiate(). Stable per-pod DNS names ([service-name]-0.internal, [service-name]-1.internal, etc.) are provided by a Kubernetes Headless Service, which is required for replica set member addressing.