Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 25, 2022 03:10 pm GMT

Prisma now offers MongoDB Support!

In very exciting news, Prisma.io recently announced the general availability of support for MongoDB. For those of you who are unfamiliar, Prisma is a next-generation objection-relational mapper (ORM) that makes development of web applications with Node.js and Typescript lightning fast. Its worth noting that Prisma is the only fully type-safe ORM in the TypeScript ecosystem. The generated Prisma client ensures typed query results even for partial queries and relations. Tinkering with it was super easy - its very developer friendly and a welcome abstraction layer for error-prone querying.

How does it work?

Every project starts with a Prisma schema file. The schema file allows developers to define application models in an intuitive data modeling language. This helps prevent data inconsistencies and bloated data models. It also contains the connection to your MongoDB database and defines a generator (the prisma client). The prisma client is an auto-generated and type-safe query builder for TypeScript (and Node.js). With autocompletion right in Prismas code editor, developers can more easily build queries of their MongoDB data without needing to look up reference documentation.

How to get started?

Despite Prisma support for MongoDB being fairly new, there are already a plethora of resources available on this topic, so I thought I would condense those into one quick guide. To get started, youll need to complete the following steps:

  1. Create a Prisma project
  2. Create a Prisma schema and start data modeling
  3. Generate a Prisma client
  4. Create an Atlas cluster
  5. Connect to your Atlas cluster
  6. Write data
  7. Query your data with the Prisma client

Note if you want to explore your data you can do that in the Prisma Studio visual editor, or you can use MongoDB Compass, or you can use the data explorer available in the Atlas UI, or you can use the MongoDB VS Code Extension... there are a lot of options here.

How does Prisma differ from Mongoose?

Mongoose is another ORM (or ODM, depending on who you ask) for MongoDB. How are they different? Which one is the better fit? Heres a simple comparison of various queries with each of them.

Most developers should find Prismas minimal API a welcome change from overly complex competitors in this space - certainly most of the features advertised, the average developer doesnt really need. Ive now built a couple of quick applications with Prisma and Node.js and I find it very intuitive and easy to get something up and running. As with all ORMs it is an abstraction layer, so you do sacrifice some flexibility in the name of usability and productivity - but I didnt hit any of those alleged limitations and Im not convinced most people would, even when building a more robust application.

We hope youll give it a try (for science!) and let us know your thoughts. We also have a whole week of activities with Prisma ahead where you can learn more about using Prisma with MongoDB - check out the launch website to learn more and join us!

You can also check out Prisma on github.


Original Link: https://dev.to/mongodb/prisma-now-offers-mongodb-support-2j54

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To