MongoDB 8 Setup
Run MongoDB 8 on Witchly.host — a document-oriented NoSQL database for modern applications. Setup, authentication, and connecting your app.
applications (9 articles)
On This Page
MongoDB 8 Setup
MongoDB is a document-oriented NoSQL database. Instead of tables and rows, you store JSON-like documents in collections. It’s the go-to database for many Node.js, Python, and full-stack applications — especially when your data shape isn’t fixed.
Witchly runs MongoDB 8 — the current stable major release. Available on Elite plans only (Free tier lacks the resource headroom).
When to choose MongoDB
- Your data is deeply nested and changes shape often.
- You’re using Mongoose, Prisma-with-Mongo, Motor, or the official driver.
- You want built-in sharding/replication paths for future scale (though single-node is fine for most apps).
Postgres or MariaDB instead? If your data is relational and fits rows/columns naturally, Postgres or MariaDB is usually the better default. Pick MongoDB when schema flexibility is a real need, not a vague one.
Deploying
- dash.witchly.host → Deploy → Applications → MongoDB 8.
- Elite only. Pick The Daemon or The Orchestrator — MongoDB benefits from RAM for its working-set cache.
- Click Deploy.
Configuring credentials
On the Startup tab:
| Variable | Value |
|---|---|
MONGO_USER | Admin username (default admin) |
MONGO_USER_PASS | Required — set a strong password |
MongoDB is started bound to 0.0.0.0 on your allocated port with authentication enabled.
Connecting
Get your server’s IP and port from the Overview tab, then:
# Mongo shell (mongosh)
mongosh "mongodb://admin:your-password@your-server-ip.witchly.host:12345"
From an application:
// Node.js — mongodb driver
import { MongoClient } from "mongodb"
const client = new MongoClient("mongodb://admin:your-password@your-server-ip.witchly.host:12345")
await client.connect()
const db = client.db("myapp")
// Node.js — Mongoose
import mongoose from "mongoose"
await mongoose.connect("mongodb://admin:your-password@your-server-ip.witchly.host:12345/myapp?authSource=admin")
# Python — Motor (async) or PyMongo
from pymongo import MongoClient
client = MongoClient("mongodb://admin:your-password@your-server-ip.witchly.host:12345")
db = client["myapp"]
Create per-app users
Never ship production code using the admin account. Inside mongosh:
use myapp
db.createUser({
user: "myapp_user",
pwd: "strong-password",
roles: [{ role: "readWrite", db: "myapp" }],
})
Then connect with mongodb://myapp_user:...@host:port/myapp.
Backups
Use mongodump for logical backups:
mongodump --uri="mongodb://admin:password@your-server-ip.witchly.host:12345" --out=./backup
mongorestore --uri="..." ./backup
Or enable Pterodactyl’s Backups tab — which archives the entire data directory. Pro tip: stop the MongoDB service first for a consistent snapshot, or use mongodump while running.
Performance tips
- Keep your working set in RAM. If
db.serverStatus().wiredTiger.cache["bytes currently in the cache"]regularly hits the cache size, upgrade your tier. - Index what you query.
db.collection.explain("executionStats").find({...})tells you if a query used an index. - Use the aggregation framework over chained
find()s for multi-stage queries.
Troubleshooting
Authentication failed— the admin user’sauthSourceisadmin. Include?authSource=adminin the connection URI if connecting to a different DB.- Can’t connect remotely — verify the port from the Overview tab.
- Oplog too small for replication — not relevant on a single-node deployment, but worth knowing if you later migrate to a replica set.
Next steps
- Backups — MongoDB data loss is brutal; don’t skip this
- Server security for best practices with passwords and ports