Database > Database Overview
Database > Database OverviewKroxt BaaS SDK v1.0.5

Database Overview

Kroxt BaaS is powered by MongoDB. Every document uploaded or fetched from your database is bound to its collection. Crucially, you must create a schema on the collection in the dashboard before you can write or receive documents. Payloads that do not match the defined schema are rejected by the validation middleware.

Prerequisites:
  • A Kroxt project running.
  • A collection created in the Kroxt Dashboard with its schema explicitly defined.

Database Console Modules

Inside the Kroxt Console, the Database workspace contains these active tools:

Overview & playground

Visualize document counts, indexes, and total storage sizing. The sandbox editor lets you insert, query, update, or remove MongoDB records directly without code.

Mandatory Schema Enforcer

A visual builder to map keys to strict type definitions (String, Number, Date, Boolean, Array, Object) ensuring schema compliance for all database operations.

Initialize Collection Reference:
db.ts
1
2
3
4
5
6
// Get reference to the todos collection
const todos = baas.collection("todos");

// Trigger a count query to verify connectivity
const count = await todos.count();
console.log("Total todos:", count);
Bring Your Own MongoDB

Don't want to use the Kroxt managed database? You can host all of your project's tenant data in your own MongoDB instance instead.

Option 1 — SDK

Pass a mongodbUri when initializing the client. The SDK registers the connection with the backend (which connects to your database server-side) and your project switches to external hosting automatically.

byo-db.ts
1
2
3
4
5
6
7
8
import { Kroxt } from "@kroxt/baas-sdk";

export const baas = new Kroxt({
  projectId: "6a8204b4875df386fb99058c",
  apiKey: "pk_dev_fb8ed3985fb842c560d7bc6fd62f8cd8d3e6f7db65e5a20a",
  // Host your project data in your own MongoDB database:
  mongodbUri: "mongodb://user:pass@host:27017/yourdb",
});

You only need to set it once. After that, the URI is stored (encrypted) on the project server-side, so later SDK inits can omit it and your data still lives in your database.

Option 2 — Dashboard

Open your project's Settings → Database Hosting, paste your connection string, and click Connect. You can revert to the Kroxt managed database anytime with the Revert button.

How it works:
  • Kroxt validates connectivity, then encrypts the URI at rest (using its JWT secret).
  • All collections, documents, users, and storage metadata are stored in your MongoDB, namespaced under kroxt_project_<projectId> so multiple projects can share one database safely.
  • API keys, billing, and auth tokens remain managed by Kroxt — only your tenant data moves.
  • Deleting a project never drops your externally hosted database.