Databases
Document Databases
MongoDB-compatible Databases built on DocumentDB: connecting with the official drivers, Namespaces, the operator-injection guard and what is refused.
A Document Database is MongoDB-compatible. It runs DocumentDB, an open-source engine that speaks the MongoDB wire protocol and stores documents in PostgreSQL. You connect with the official MongoDB drivers and a mongodb:// Connection URL.
A Document Database is PostgreSQL underneath, run by DocumentDB. Today it has fewer features than an SQL Database, and this page says exactly which:
| SQL Database | Document Database | |
|---|---|---|
| Standby with Failover | Yes | Yes |
| Backups | Continuous, restore to any second | Every 6 hours, kept for your Plan's restore window |
| Restore | From the console or the API, to any second | By request in the chat, to one of the 6-hourly backups, as a new Database |
| Replicas in other Regions | Yes | Not yet |
| Credentials | Four presets and Grants | read_only or read_write, no Grants |
| Reads, Writes and Egress counted | Yes | Not yet: they are not counted against your Plan |
Compatibility is partial
DocumentDB implements a large part of MongoDB's commands and query language, not all of it. Test your app against a Document Database before you move production data. A list of supported commands will be published on this page.
We call it MongoDB-compatible because it is not MongoDB.
Connecting
The Connection URL for a Document Database:
mongodb://cr_4k2m8p0d9a:nbs_…@db-k7q2x9m4p1.fi-hel.nordbase.<base>:27017/?tls=true&authMechanism=SCRAM-SHA-256- Port 27017 speaks the MongoDB wire protocol.
tls=true: the Endpoint finds your Database by the TLS server name (SNI). Your system's certificates are enough.authMechanism=SCRAM-SHA-256: the Credential id is the username, the secret the password.
Any official driver takes the URL unchanged:
// Node, official driver
import { MongoClient } from 'mongodb'
const client = new MongoClient(process.env.NORDBASE_URL!)
const orders = client.db('shop').collection('orders')
const order = await orders.findOne({ number: 'SO-24117' })# Python, official driver
import os
from pymongo import MongoClient
client = MongoClient(os.environ["NORDBASE_URL"])
orders = client["shop"]["orders"]
order = orders.find_one({"number": "SO-24117"})// Rust, official driver
use mongodb::{bson::{doc, Document}, Client};
let client = Client::with_uri_str(std::env::var("NORDBASE_URL")?).await?;
let orders = client.database("shop").collection::<Document>("orders");
let order = orders.find_one(doc! { "number": "SO-24117" }).await?;mongosh works too:
mongosh "$NORDBASE_URL"Namespaces
A Namespace is what a MongoDB driver calls a database: the name you pass to client.db('shop'). One NordBase Database can hold many Namespaces, each with its own collections.
Namespaces matter for access: a Grant can allow or deny a Credential on a whole Namespace or on one collection inside it.
The operator-injection guard
The usual injection in document databases is an operator object hidden in request JSON. A login form that passes the request body straight into a filter:
{ "email": "[email protected]", "password_hash": { "$ne": null } }{ "$ne": null } matches any password, so the filter logs anyone in. The NordBase libraries wrap the official driver and refuse this:
-
In filters and updates, a value that arrives as a plain object with a key starting with
$is refused withUnsafeFilterError. Nothing is sent. -
Operators are written with helpers that produce trusted values. Plain JSON can never produce one:
tsimport { op } from 'nordbase' const filter = { status: 'paid', total: op.gt(100), region: op.in(['fi-hel', 'de-fsn']) } -
Field names that come from variables are checked: no leading
$, no NUL character, and no.unless you pass the path as an array of parts. -
Helpers for ObjectId, dates and decimals make sure a JSON value cannot stand in for one of them with an operator object.
-
Optionally, each collection can have a schema, checked before every insert and update. Node uses Standard Schema (Zod, Valibot), Python uses Pydantic, Rust uses serde.
The Document client
Each library has a Document client that reads NORDBASE_URL, wraps the official driver and applies the guards above. Pick a Namespace with db(...), then a collection:
import { createDocumentClient, op } from 'nordbase'
const client = createDocumentClient() // reads NORDBASE_URL
const carts = client.db('app').collection('carts')
const open = await carts.find({ user: userId, total: op.gt(0) })
await carts.updateOne({ _id: cartId }, { $set: { paid: true } })from nordbase import connect_document, op
client = connect_document() # reads NORDBASE_URL; connect_document_async() for asyncio
carts = client.db("app").collection("carts")
open_carts = carts.find({"user": user_id, "total": op.gt(0)})
carts.update_one({"_id": cart_id}, {"$set": {"paid": True}})use nordbase::{DocumentClient, DocumentOptions};
let client = DocumentClient::connect(DocumentOptions::default()).await?; // reads NORDBASE_URL
let carts = client.db("app").collection("carts");
let open = carts.find(doc! { "user": user_id }).await?;Top-level update operators such as $set, $inc and $push are written in code; below them, any $ key in a value is refused, so $push with $each uses op.each([...]). Combine conditions with op.or([...]) and op.and([...]), not with plain $or objects.
If you use the official driver directly instead, never pass request JSON into a filter or update: read the fields you expect and check their types first.
Always refused
These run JavaScript on the Database and are refused in every form, in filters, updates and aggregation pipelines:
$where$function$accumulator- any other server-side JavaScript
Reads, Writes and Replicas
- Every document command counts once, as a Read or a Write, however many documents it touches. An
updateManythat changes 5,000 documents is one Write; aninsertManyof 200 documents is one Write. Drivers fetch largefindresults in batches, and each batch is its own command. - All Reads and Writes on a Document Database go to the Primary. Replicas for Document Databases come later.
- If the Primary fails and the Database has a Standby, the Standby takes over, as for SQL Databases.
- Reads, Writes and Egress of Document Databases are not counted yet, so they never throttle. Storage is counted.
Running a command through the API
The management API and the MCP server can run one MongoDB command document against a Namespace, for the console and AI agents. See POST /v1/databases/{database_id}/query in the API reference.
Patterns and aggregation
- Regular expressions that arrive in JSON (
$regex,$regularExpression) are refused like any operator. Write patterns withop.regex('^ana', 'i'). - In aggregation pipelines,
$matchfollows the filter rules at any depth, including inside$facetand$lookup.$outand$mergeare refused. Other stages are taken as written, so never build a pipeline stage from input outside$match. - Writes are never retried automatically: if the connection drops during a Write, the error says the outcome is unknown.