question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for $jsonSchema for mongodb

See original GitHub issue

Problem

Prisma currently does not support a mongodb json schema, is there any plan to add support to it?

Suggested solution

Having $jsonSchema support would be nice to have safe guarantees over the integrity of our data (when using an external tool, or performing raw aggregation operations, etc.).

It would also enable existing databases migration that rely on this feature (currently my case).

Finally it could also enable easy introspection of an existing database and help on other subjects as well, if it makes things simpler/safer, I think it could make sense to have it enabled by default and drop support for schema-less mongodb databases.

Additional context

One major pain point when dealing with jsonSchema was the lack of proper error reporting when an operation fails, would not impact end user that much thanks to the type-safety but would have been harder to develop / test, it has been fixed in SERVER-20547 that landed in 4.9.0.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:11
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
dimaipcommented, May 10, 2022

IMO this is a crucial feature for Prisma+Mongo combination. Currently it’s very easy to run into runtime validation failures (even on read!) due to invalid data in the database. The problem comes from the fact that relational databases make it technically impossible to have invalid data not conforming to the schema in the database, and with Mongo we have no such guarantees unless we use $jsonSchema, which makes things super fragile. We’ve been running into terrible crashes in production, where in staging it all worked fine and then due to some slightly incorrect record everything blew up.

1reaction
dimaipcommented, Jul 6, 2022

So I’ve forked prisma-json-schema-generator and:

  • made it produce the JSON schema in flavour which Mongo understands
  • added some scripts to automatically apply the schema to collections and validate their contents

https://github.com/joindeed/prisma-mongo-json-schema-generator

Feel free to experiment with it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

$jsonSchema — MongoDB Manual
Keyword Type Definition additionalItems arrays boolean or object additionalProperties objects boolean or object allOf all types array of JSON Schema objects
Read more >
How to use $jsonSchema operator in MongoDB - Linux Hint
Apart from retrieving, the $jsonSchema operator can be used to define the set of rules for insertion operation in MongoDB. Any insert query...
Read more >
How to Create and Validate JSON Schema in MongoDB ...
From Version 3.6, MongoDB supports this standard and provides a JSON Schema Validator from within the application that runs like a trigger ...
Read more >
How To Use Schema Validation in MongoDB - DigitalOcean
Applying a JSON Schema validator from the start like this means every document you add to the collection must satisfy the requirements set ......
Read more >
MongoDB Data Validator: How to Use the JSON Schema ...
We just need to insert a JSON document into a collection and that's all. Documents in the same collection can have a completely...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found