Skip to content

fix(family-mongo): db schema prints a field with several BSON types as a | b - #30476

Merged
wmadden-electric merged 4 commits into
prisma:mainfrom
lazerg:fix/issue-30470-mongo-bson-type-list
Nov 12, 2026
Merged

wmadden-electric merged 4 commits into
prisma:mainfrom
lazerg:fix/issue-30470-mongo-bson-type-list

Conversation

@lazerg

@lazerg lazerg commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor
# before
meta: object,array,string,double,int,long,bool,null
note: null,string

# after
meta: object | array | string | double | int | long | bool | null
note: null | string

db schema on MongoDB now joins the BSON types of a multi-type validator property with |.

Why

A MongoDB $jsonSchema property can allow several BSON types: a Json field allows all of them, and a nullable field allows its type and null. db schema printed that list joined with bare commas, which is hard to read and looks like a typo. The | form reads as "one of these", like a TypeScript union.

The change

After merging main this is a one-line change in schema-to-view.ts: the type list is joined with ' | ' instead of ','. Since this PR was opened, main started collecting each field's types across all of a collection's root models. That list goes through the same join, so the anyOf case is covered too. A property with a single type, and the any fallback, print as before. The Postgres view has no multi-type case, because a Postgres column has exactly one type.

Tests

  • test/integration/test/mongo/db-schema.test.ts creates a collection on mongodb-memory-server with a multi-type property and a nullable property, introspects it, and checks the printed labels. It fails on main and passes here. 10 tests pass.
  • A unit case in packages/2-mongo-family/9-family/test/control.test.ts covers the same two properties.

Alternatives considered

  • object, array, … with spaces. Easier on the eye than bare commas, but it doesn't say "one of these".
  • One line per type. This breaks the one-field-per-line layout the view uses for both families.

Fixes #30470

@lazerg
lazerg requested a review from a team as a code owner September 28, 2026 11:13
@coderabbitai

coderabbitai Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The MongoDB schema view now joins validator BSON types with |. Unit and integration tests cover multiple types, nullable properties, type order, and required-property markers.

Changes: MongoDB BSON type labels

Layer / File(s) Summary
Format validator type labels
packages/2-mongo-family/9-family/src/core/schema-to-view.ts, packages/2-mongo-family/9-family/test/control.test.ts, packages/2-mongo-family/9-family/test/schema-to-view.test.ts, test/integration/test/mongo/db-schema.test.ts
Validator field labels join BSON types with `

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: wmadden-electric

Merge Risk: Minimal · up to 70963

Multiple BSON types now display with pipe separators. No merge-blocking risk is identified.

Architecture risk: Low · up to 63592

The change affects 2 systems.

Changed systems: packages/2-mongo-family, test

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — packages/2-mongo-family (library) was modified; 2 changed files map to changed impact.
  • observed — test (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in packages/2-mongo-family/9-family/src/core/schema-to-view.ts: Adds the local bsonTypeLabel formatter, which handles missing values, arrays, and other values separately.
  • observed — Modified behavior in packages/2-mongo-family/9-family/src/core/schema-to-view.ts: Validator field labels now use bsonTypeLabel; array-valued types are joined with | rather than converted directly to a string.
  • observed — Modified behavior in packages/2-mongo-family/9-family/test/control.test.ts: Adds a toSchemaView test asserting that multi-type BSON property labels join their types with | in input order, and retain the required suffix; the examples cover eight types and null | string.
  • observed — Modified behavior in test/integration/test/mongo/db-schema.test.ts: Adds an integration test for multi-type validator properties. It verifies the schema view renders payload as object | array | string | double | int | long | bool | null (required) and note as null | string.
Pre-merge checks: Passed 4

Check name Status Explanation
Linked Issues check Passed Issue #30470 requires readable labels for validator properties with multiple BSON types and tests for list-typed and nullable properties. schema-to-view.ts joins BSON types with | and preserves …
Out of Scope Changes check Passed The diff changes MongoDB validator type labels and adds focused unit, expected-output, and integration tests for issue #30470. The changes have a direct connection to the issue. No unrelated changes a…
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title states the main change: MongoDB db schema output for a field with several BSON types now shows the types joined as a | b. It uses the conventional fix(scope) prefix and matches the summa…
Full details: Linked Issues check

Explanation

Issue #30470 requires readable labels for validator properties with multiple BSON types and tests for list-typed and nullable properties. schema-to-view.ts joins BSON types with | and preserves the any fallback. The unit and integration tests cover a multi-type property and a nullable property, including the required marker.

Full details: Out of Scope Changes check

Explanation

The diff changes MongoDB validator type labels and adds focused unit, expected-output, and integration tests for issue #30470. The changes have a direct connection to the issue. No unrelated changes appear in the diff.

Full details: Title check

Explanation

The title states the main change: MongoDB db schema output for a field with several BSON types now shows the types joined as a | b. It uses the conventional fix(scope) prefix and matches the summary, the test changes, and the linked issue #30470. The title is 78 characters, which is slightly long but still clear.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: prisma/orm
  • Branch: main
  • File: .coderabbit.yml
  • Commit: e118f38
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0d21c231-e820-451f-9a37-7f77d18097df
Commits

Reviewing files that changed from the base of the PR and between 63592e2 and 7096316.

Files selected for processing: 3

  • packages/2-mongo-family/9-family/src/core/schema-to-view.ts
  • packages/2-mongo-family/9-family/test/control.test.ts
  • packages/2-mongo-family/9-family/test/schema-to-view.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

@lazerg

lazerg commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

@wmadden, please have a look when you have time

wmadden-electric and others added 2 commits November 11, 2026 08:00
main rewrote schema-to-view.ts to union each field's types across the
validator's root models; the fix now applies to that join. The unit test
passes the fromDatabase option MongoSchemaIR now requires.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…ests from main

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@pkg-pr-new

pkg-pr-new Bot commented Nov 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

@prisma/orm-extension-arktype-json

npm i https://pkg.pr.new/prisma/orm/@prisma/orm-extension-arktype-json@30476

@prisma/orm-extension-middleware-cache

npm i https://pkg.pr.new/prisma/orm/@prisma/orm-extension-middleware-cache@30476

@prisma/orm-extension-paradedb

npm i https://pkg.pr.new/prisma/orm/@prisma/orm-extension-paradedb@30476

@prisma/orm-extension-pgvector

npm i https://pkg.pr.new/prisma/orm/@prisma/orm-extension-pgvector@30476

@prisma/orm-extension-postgis

npm i https://pkg.pr.new/prisma/orm/@prisma/orm-extension-postgis@30476

@prisma/orm-extension-supabase

npm i https://pkg.pr.new/prisma/orm/@prisma/orm-extension-supabase@30476

@prisma/orm-family-mongo

npm i https://pkg.pr.new/prisma/orm/@prisma/orm-family-mongo@30476

@prisma/orm-family-sql

npm i https://pkg.pr.new/prisma/orm/@prisma/orm-family-sql@30476

@prisma/orm-framework

npm i https://pkg.pr.new/prisma/orm/@prisma/orm-framework@30476

@prisma/orm-mariadb

npm i https://pkg.pr.new/prisma/orm/@prisma/orm-mariadb@30476

@prisma/orm-mongo

npm i https://pkg.pr.new/prisma/orm/@prisma/orm-mongo@30476

@prisma/orm-mysql

npm i https://pkg.pr.new/prisma/orm/@prisma/orm-mysql@30476

@prisma/orm-postgres

npm i https://pkg.pr.new/prisma/orm/@prisma/orm-postgres@30476

@prisma/orm-postgres-contrib

npm i https://pkg.pr.new/prisma/orm/@prisma/orm-postgres-contrib@30476

@prisma/orm-sqlite

npm i https://pkg.pr.new/prisma/orm/@prisma/orm-sqlite@30476

@prisma/orm-target-mariadb

npm i https://pkg.pr.new/prisma/orm/@prisma/orm-target-mariadb@30476

@prisma/orm-target-mongo

npm i https://pkg.pr.new/prisma/orm/@prisma/orm-target-mongo@30476

@prisma/orm-target-mysql

npm i https://pkg.pr.new/prisma/orm/@prisma/orm-target-mysql@30476

@prisma/orm-target-postgres

npm i https://pkg.pr.new/prisma/orm/@prisma/orm-target-postgres@30476

@prisma/orm-target-sqlite

npm i https://pkg.pr.new/prisma/orm/@prisma/orm-target-sqlite@30476

@prisma/orm-toolchain

npm i https://pkg.pr.new/prisma/orm/@prisma/orm-toolchain@30476

commit: 7096316

@wmadden-electric wmadden-electric changed the title fix(mongo): print a multi-type validator property as a | b in db schema fix(family-mongo): db schema prints a field with several BSON types as a | b Nov 12, 2026
@wmadden-electric
wmadden-electric added this pull request to the merge queue Nov 12, 2026
Merged via the queue into prisma:main with commit 2407cf4 Nov 12, 2026
25 checks passed
@prisma-asks

prisma-asks Bot commented Nov 17, 2026

Copy link
Copy Markdown

This is fixed. db schema now prints a MongoDB field that allows several BSON types as a | b. The fix merged to main in #30476.

You can follow where this stands here: https://asks.prisma.cool/public/asks/01a13059-316f-7198-a2e1-edd2a3abdfec

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

db schema prints a Mongo field that admits several BSON types as a comma-joined word

3 participants