MongoDB
DocsDatabasesMongoDB

MongoDB

MongoDB-compatible database on StackBlaze, served by DocumentDB, with TLS and SCRAM-SHA-256 required on port 10260.

Powered by DocumentDB

MongoDB on StackBlaze is served by DocumentDB, a MongoDB wire-protocol–compatible engine built on PostgreSQL. You connect with the standard MongoDB drivers and tools (mongosh, Compass, Mongoose, Prisma, Motor). We use DocumentDB so we can ship a MongoDB-compatible database under a permissive license.
Adding MongoDB from the Databases catalog and attaching it to the app injects MONGO_HOST, MONGO_DB, and MONGO_URL.

Creating a MongoDB instance

From the project canvas, click + ServiceDatabasesDocument 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.

VariableRole
MONGO_HOSTGateway hostname
MONGO_PORT10260
MONGO_USERNAMEDatabase user
MONGO_PASSWORDPassword

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

Prefer the injected URI when it is present. If you connect from the discrete variables, point your driver at 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.

Open with DB Beaver launches a scoped CloudBeaver session where the users table is browsed, a query runs, and the results appear.

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.

Create indexes (Mongoose)
// 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

db.ts
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.

prisma/schema.prisma
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)

database.py
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

DocumentDB speaks the MongoDB wire protocol on port 10260 with TLS and SCRAM-SHA-256. Attached apps should use the injected variables or URI — do not hardcode port 27017.