Skip to content

Latest commit

 

History

History
65 lines (43 loc) · 2.15 KB

File metadata and controls

65 lines (43 loc) · 2.15 KB

Prisma Mongo JSON Schema Generator

This package contains two things:

Why?

Because Prisma would blow up at the very wrong moment if the underlying data is invalid. Read this thread to understand the problem better:

image

Credit

This package is a fork of prisma-json-schema-generator, an amazing work by Valentin Palkovic!

Getting Started

1. Install

npm:

npm install prisma-mongo-json-schema-generator --save-dev

yarn:

yarn add -D prisma-mongo-json-schema-generator

2. Apply the schema to database

PRISMA_SCHEMA_FILE=prisma/prisma.schema MONGO_URI=mongodb://localhost:27017/your-database yarn prisma-mongo-json-schema-generator-apply

If you are getting AuthenticationFailed errors, make sure that you are specifying the correct auth database in the connection URI by using the authSource query parameter (ex: authSource=admin).

The package is configurable via environment variables:

Env name Default value
MONGO_URI required
PRISMA_SCHEMA_FILE prisma/prisma.schema
VALIDATION_LEVEL strict
VALIDATION_ACTION error

If you want to omit some property from being included in the schema, add @MongoSchema.omit to its documentation in the Prisma schema:

model SomeModel {
  /// @MongoSchema.omit
  someProperty String
}

3. Validate collections according to the schema

PRISMA_SCHEMA_FILE=prisma/prisma.schema MONGO_URI=mongodb://localhost:27017/your-database yarn prisma-mongo-json-schema-generator-verify