Prisma now offers MongoDB Support!
Tags: prisma, javascript, typescript, mongodb
Published: 2022-04-25 15:10:23

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. It’s 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 - it’s very developer friendly and a welcome abstraction layer for error-prone querying. 

## How does it work?
Every project starts with a [Prisma schema file](https://www.prisma.io/docs/concepts/components/prisma-schema). 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 Prisma’s 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, you’ll need to complete the following steps:

1. [Create a Prisma project](https://www.prisma.io/docs/getting-started/setup-prisma/start-from-scratch/mongodb-typescript-mongodb)
2. [Create a Prisma schema and start data modeling](https://www.prisma.io/docs/concepts/components/prisma-schema)
3. [Generate a Prisma client](https://www.prisma.io/docs/concepts/overview/what-is-prisma#accessing-your-database-with-prisma-client)
4. [Create an Atlas cluster](https://www.prisma.io/dataguide/mongodb/mongodb-atlas-setup)
5. [Connect to your Atlas cluster](https://www.prisma.io/docs/getting-started/setup-prisma/start-from-scratch/mongodb/connect-your-database-typescript-mongodb)
6. [Write data](https://www.prisma.io/docs/getting-started/setup-prisma/start-from-scratch/mongodb/querying-the-database-typescript-mongodb#write-data-into-the-database)
7. [Query your data with the Prisma client](https://www.prisma.io/docs/getting-started/setup-prisma/start-from-scratch/mongodb/querying-the-database-typescript-mongodb)

Note if you want to explore your data you can do that in the Prisma Studio visual editor, or you can use MongoDB [Compass](https://www.mongodb.com/try/download/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? Here’s [a simple comparison](https://www.prisma.io/docs/concepts/more/comparisons/prisma-and-mongoose) of various queries with each of them.

Most developers should find Prisma’s minimal API a welcome change from overly complex competitors in this space - certainly most of the features advertised, the average developer doesn’t really need. I’ve 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 didn’t hit any of those alleged limitations and I’m not convinced most people would, even when building a more robust application.

We hope you’ll 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](https://www.prisma.io/mongodb-launch) to learn more and join us!

You can also check out Prisma on [github](https://github.com/prisma/prisma).