DEV Community

Discussion on: What technologies are you currently learning?

 
ajcwebdev profile image
ajcwebdev

Status of RedwoodJS and MongoDB as of Early 2022

I know this is a very old comment, but I found it on the first page of Google while searching "RedwoodJS MongoDB", so I thought it might be worth including some current info for anyone else stumbling upon it today.

Should You Connect to MongoDB with Realm?

It is absolutely true that anything exposed through a GraphQL endpoint can be queried from Redwood's API in a straightforward manner with something like node-fetch or graphql-request. This is a useful way to bring in data from a third party service. You can ignore Prisma entirely, even deleting the Prisma folder containing your database schema.

But in most cases it's not really a good idea to do this. This means you leave behind the Prisma ORM entirely as your primary database tool and instead only query through a GraphQL API. I know this from experience, as I've done this on a number of example applications with tools such as Fauna and StepZen.

Problems with Extracting Prisma

There are two main reasons why circumventing Prisma entirely is usually a bad idea:

  • You lose out on a lot of the functionality of Redwood's CRUD scaffolding capabilities since you aren't building from a Prisma model.
  • Depending on what database is exposed through that endpoint and how the data is structured, GraphQL can be a sub-optimal query language.
    • This isn't because GraphQL is bad (it pays my bills actually).
    • However, it can be limiting in comparison to the native query languages these databases actually contain.
    • In this case that query language is MQL, the MongoDB Query Language.

Prisma Now Supports MongoDB

When this comment was originally written in October 2020, Realm was the only way to connect to a Mongo database with Redwood at all. However, Prisma officially added support for MongoDB in 2021.

This means that you can now use MongoDB in your Redwood project as your entire backend, scaffold commands included. While still a layer of abstraction removed from MQL, it is a full ORM closer in spirit to Mongoose.

Still In Progress

Unfortunately, while this is possible today it is lacking currently in proper Redwood documentation. All the material are out there for those who are determined enough to piece it together but there isn't an end to end tutorial yet.

However, if you are interested in using RedwoodJS and MongoDB today and want to provide early feedback, we have a cookbook in the works along with an open issue.

Relevant Prisma Links

Relevant Redwood Links