Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.dbdock.xyz/llms.txt

Use this file to discover all available pages before exploring further.

Cross-database migration requires a type system translation. This page documents exactly how DBdock maps types in both directions.

MongoDB → PostgreSQL

Scalar types

BSON typePostgres typeNotes
ObjectIduuid or textStored as hex string. Use uuid if you plan to keep the ID format.
StringtextLength-agnostic. Use varchar(n) if you need a limit.
Int, LongbigintSafe default for JS numeric ranges.
Double, Decimal128double precision or numericnumeric preserves exact precision.
BooleanbooleanDirect map.
DatetimestamptzAlways stored as UTC.
BinarybyteaBinary data.
nullNULLColumn must be nullable.

Container types

BSON typePostgres typeNotes
Object (nested)Flattened columns or jsonbDepth ≤ --max-depth → flatten; deeper → jsonb.
Array<T>T[] (native array) or jsonbHomogeneous arrays of scalars → native array; mixed → jsonb.
Array<Object>jsonbAlways jsonb — one-to-many relationships aren’t auto-derived.

Mixed types

If a field has multiple types across documents (e.g., 99% Int, 1% Double), DBdock picks the “widest” compatible Postgres type. You’ll see a warning:
⚠️ users.age: mixed Int/Double → chose double precision
You can override this by editing the exported config file.

Example

MongoDB:
{
  "_id": ObjectId("..."),
  "email": "alice@example.com",
  "profile": {
    "name": "Alice",
    "avatar_url": "https://..."
  },
  "tags": ["admin", "beta"],
  "metadata": {
    "deep": {
      "nested": { "value": 1 }
    }
  }
}
Postgres (with --max-depth 2):
CREATE TABLE users (
  id          uuid PRIMARY KEY,
  email       text UNIQUE NOT NULL,
  profile_name       text,
  profile_avatar_url text,
  tags        text[],
  metadata    jsonb  -- deep nesting preserved as JSON
);

PostgreSQL → MongoDB

Scalar types

Postgres typeBSON typeNotes
uuidStringUUID as lowercase hex string.
text, varcharStringDirect map.
integer, bigintInt / Longbigint may need Long on 32-bit platforms.
numeric, decimalDecimal128Exact precision preserved.
real, double precisionDoubleIEEE 754 mapping.
booleanBooleanDirect map.
dateDate (at midnight UTC)Date-only types lose time component.
timestamp, timestamptzDateStored as UTC.
byteaBinaryDirect map.
jsonb, jsonNative documentParsed into MongoDB object.

Container types

Postgres typeBSON typeNotes
T[] (array)Array<T>Element types mapped individually.
Foreign key relationsOption: embed or referenceSee below.

Relationships

DBdock can optionally embed one-to-many relationships into parent documents:
  • Reference mode (default): stores the FK as-is, creates separate collections.
  • Embed mode: pulls child rows into a nested array on the parent document.
Configure per-table in the exported config file.

Example

Postgres:
CREATE TABLE users (
  id     uuid PRIMARY KEY,
  email  text UNIQUE
);

CREATE TABLE posts (
  id      uuid PRIMARY KEY,
  user_id uuid REFERENCES users(id),
  title   text,
  body    text
);
MongoDB (reference mode):
// users collection
{ _id: "...", email: "alice@example.com" }

// posts collection
{ _id: "...", user_id: "...", title: "...", body: "..." }
MongoDB (embed mode):
// users collection (posts embedded)
{
  _id: "...",
  email: "alice@example.com",
  posts: [
    { _id: "...", title: "...", body: "..." }
  ]
}

Customizing the mapping

Export the generated plan:
npx dbdock migrate "$SRC" "$DST" --export-config ./migration.json
Edit the file — change column types, rename fields, flag embeds, skip collections. Then run with the custom config:
npx dbdock migrate "$SRC" "$DST" --config ./migration.json
Commit the config file to git so your team uses the same mapping.