ORM for MongoDB - Mongoose or Prisma
I have been using Mongoose as my ORM to define my database schema for a very long time. As I'm coming from a SQL background, even when I started using No-SQL, my preference was towards having a neat schema. I noticed that many projects directly used mongo libraries on their NodeJS projects and did not have any ORM as such. I wanted to use ORM and back then mongoose was one of the famous libraries. But today when we just google ORM for MongoDB, the first thing we are getting is Prisma.
Most of my projects use mongoose and only recently have I started exploring Prisma as an alternative to mongoose. I believe it is not just me but many people have started switching to mongoose when they want to write backend applications connecting to MongoDB. The biggest and primary advantage we have with Prisma is that we can switch from one database to another database without disturbing our backend code. Of course, there will be data dependencies for a live application and migration might be required, but it is good to switch between SQL and No-SQL if someone really wants to do it.
The default setup will be having a connection string pointing to the Postgres database. But we can update it to other SQL or No-SQL databases. This way we don't really have to do major changes to our code or the schema and for some databases, if we just change the connection string, the application would be intact and work fine. I'm sure they would be bringing support for more databases in the future.
Prisma documentation
The first impressive thing about Prisma is the documentation. As I'm familiar with mongoose, I was wondering if it would be possible to easily switch and understand Prisma but I should say that the documentation was very good and anyone reading the documentation should be able to get the basic ideas as to how things can work. There is also a section in the documentation that helps people who would like to switch from other ORMs to Prisma.
Drawbacks of Prisma
As Prisma is built with Typescript, there was no documentation clearly available for JavaScript developers. The examples the documentation had was for typescript users and I felt there was a slight push toward using typescript. People who know how to compare both and understand may not have any problem in converting the typescript examples to JavaScript in their code. Others who are very new to programming and new to typescript might find it challenging.
The biggest disadvantage that Prisma has is that all the schema can be written only in one file. For smaller projects, this is not a big deal but for bigger projects that are going to have nearly 100 tables or collections, it is going to be a nightmare to work on one huge file. There is no inbuilt facility to split the schema file into multiple schema files. There are workarounds available but there is no native support there is an issue available on GitHub but it is pending for over 3 years.
If you like what I'm doing on Hive, you can vote me as a witness with the links below.
|
|
|
|
|
|
View or trade
BEER
.Hey @bala41288, here is a little bit of
BEER
from @pixresteemer for you. Enjoy it!Did you know that <a href='https://dcity.io/cityyou can use BEER at dCity game to buy cards to rule the world.
If you are working with a document-based database like MongoDB, Mongoose is probably the better choice. If you are working with a relational database, Prisma might be a better fit. Now it depends on you which to choose.
I hate things that arent to well documented! lol
!1UP
You have received a 1UP from @gwajnberg!
@leo-curator, @bee-curator, @stem-curator, @vyb-curator, @pob-curator, @neoxag-curator, @pal-curator
And they will bring !PIZZA 🍕.
Learn more about our delegation service to earn daily rewards. Join the Cartel on Discord.
I gifted $PIZZA slices here:
@curation-cartel(12/20) tipped @bala41288 (x1)
Learn more at https://hive.pizza!