MongoDB
MongoDB-compatible database on StackBlaze, served by DocumentDB, with TLS and SCRAM-SHA-256 required on port 10260.
Powered by DocumentDB
Creating a MongoDB instance
From the project canvas, click + Service → Databases → Document DB. Stage the add-on, then click Commit.
To attach it to an app, use the add-on's Connections list or the app's Add-ons tab. StackBlaze injects connection environment variables into the app. There is no Environment tab → Attach database flow. To inspect or add your own variables, use the app's Variables tab.
Injected environment variables
Every attached app receives discrete host and credential variables. The gateway listens on port 10260 and requires TLS plus SCRAM-SHA-256. Plaintext connections on 27017 will not work.
| Variable | Role |
|---|---|
| MONGO_HOST | Gateway hostname |
| MONGO_PORT | 10260 |
| MONGO_USERNAME | Database user |
| MONGO_PASSWORD | Password |
When you supplied a password literal at create time, StackBlaze also injects ready-to-use URIs that already include TLS and SCRAM-SHA-256: MONGODB_URI, MONGO_URL, and DATABASE_URL. There is no MONGODB_URL.
Tip
MONGO_HOST:10260 and enable TLS and SCRAM-SHA-256.Browse and query with CloudBeaver
Every database add-on ships with CloudBeaver. Open with DB Beaver on the add-on's Overview starts a scoped session where you can browse tables, run SQL, and edit data in the browser.
Backups
Backups are not enabled automatically. Open the add-on, go to the Backups tab, and click Enable backups. From there you can use Backup now, Restore, and Schedule.
Restore always creates a new instance — there is no in-place restore. After the new instance is ready, switch the app connection to it from the add-on Connections list or the app Add-ons tab.
For the full backup workflow, see Backups & recovery.
Indexes
Create indexes in your application startup code or migration scripts. For large collections, create indexes in the background so you do not block reads and writes.
// 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'
const uri =
process.env.MONGODB_URI ||
process.env.MONGO_URL ||
process.env.DATABASE_URL
if (!uri) {
throw new Error('Set a password at create time so MONGODB_URI is injected')
}
if (mongoose.connection.readyState === 0) {
await mongoose.connect(uri, {
serverSelectionTimeoutMS: 5000,
socketTimeoutMS: 45000,
})
}Prisma (MongoDB provider)
Prisma reads a URL. Use DATABASE_URL or MONGODB_URI when they were injected.
datasource db {
provider = "mongodb"
url = env("DATABASE_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
uri = os.environ.get("MONGODB_URI") or os.environ.get("MONGO_URL") or os.environ["DATABASE_URL"]
client = AsyncIOMotorClient(uri)
db = client.get_default_database()Under the hood