Recommendations for MongoDB Driver and Schema solutions?

Attempting to fan a personal :fire:of inspiration today -->

what would it take to use MongoDB with the Redwood Tutorial (as a replacement for Prisma + SQLite/Postgres)?

Looking for tooling recommendations

  • data modeling & schema validation
  • CRUD
  • Hosting: I’m already sold on MongoDB Atlas (probably just connect locally and skip local setup for now)

Option 1: Do it all with MongooseJS

It’s been years, but I have prior experience with Mongoose ODM. So that could work.

Option 2: MongoDB NodeJS driver +

The native driver looks like it’s come a loooonggg way. So maybe a setup like:

  1. Native Driver CRUD
  2. Data Modeling / Schema Validation
    • Native Schema Validation: could this be done in my project code and “run” similar to how Prisma Migrations are done? I really don’t want to have to use a dashboard to manage the schema
    • Joi looks super interesting for Schema/modeling validation
  3. Indexing: What’s the current state on having to manually manage Indexes… do I need to worry about handling that, too?

Option 3: X

Anything else that’s obvious and I should know about?

When I looked into this myself I thought the MongoDB Realm GraphQL API could be a possible solution. You’d likely have the limitations that come along with GraphQL but on the flip side it probably would be fairly simple to spin up compared to a driver. It looks like it’s well integrated with Atlas as well.

1 Like

Yeah, that used to be called “Stitch” and it’s cool product for sure. If I were building Gatsby or Next, I’d just use Stich effectively as my serverless API.

But, if I actually attempt to do this, I want to connect directly and use the Redwood API. Make sense?

Hmm kind of, I’m a little confused by what you mean when you say “use the Redwood API directly.” Do you mean that Realm would basically be the Redwood client making requests and bypassing the Redwood API side?

Ah, sorry about the confusion. I don’t want to have the Redwood API connect to the Realm API that’s connected to MongoDB. I just want to have Redwood API <–> MongoDB.

The best use case for Realm (as I understand it) is as it’s own serverless API for your Client to connect to. So you could effectively just have Redwood Web connect to Realm and drop the need for the Redwood API. This is why it seems like a good API/backend for Gatsby and Next apps.

Cool thanks that definitely makes sense!

1 Like

I"m looking to use it with MongoDB too. Just started today. Did you make any progress on this? I’d love to know how you configured it to work directly with MongoDB.

I will say that one of the issues I’d imagine that’s a huge impediment to what you are trying to do is that the API is setup to use GraphQL as it’s interface to the DB I think and that’s not necessary with MongoDB. I think you’d have to throw out the whole pre-configured API portion of the project, install mongoosejs as you suggested in Option 1 and then connect to MongoDB from there.

Not sure if this would create a bigger mess than either of us would want to take on, but it’s been something I thought was odd from the beginning that they don’t just use the CLI to ask which DB you want. Maybe it’s too much to ask at this stage, but regardless it’s what I’d hoped for.

Hi @misterhtmlcss welcome to the Redwood community! I’m on the Redwood Core Team — happy to help you find your way around and get settled in beyond any DB questions as well. Reach out anytime.

the API is setup to use GraphQL as it’s interface to the DB

^^ this is (thankfully) not correct. For reference, here’s a diagram of Redwoods Architecture. Even though Redwood’s API is a GraphQL endpoint, it’s connecting directly to the DB (by default using Prisma). Swap out prisma with mongoosejs in the diagram and you’re off to the races.

Given that there’s a lot of additional goodness that comes with Redwood’s API structure, I’m just not sure Mongoose is even needed — it’s probably overkill. Thus my curiosity about using the MongoDB NodeJS driver.

Make sense?

1 Like

Having fiddled around myself with connecting Redwood to a database that veers off the happy path I think until you try to build a simple app with both approaches you’ll have a hard time predicting ahead of time what the pros and cons are of different approaches.

I don’t have much experience with Mongoose but the question I would ask is how many things in the core tutorial would you be able to do with just the Node driver versus bringing in something like Mongoose? If the Node driver can get through the same flow without too many extra steps than Mongoose would probably be overkill.

2 Likes

Thank you for the warm welcome. I’ll definitely reach out.

Also I’ll definitely try it. I’m going to spin up a small little todo app using RedwoodJS and Mongoose/mongoDB.

@ajcwebdev you make a great point. I think you always need to consider which tool is best. For me and my typical stack I find Mongoose is usually the best choice so I usually practice everything with it, just so I’m always becoming better with the tool. And yes a todo app doesn’t need Mongoose, but the next app might and I’d like to get that experience under my belt first. Wouldn’t you agree?

Thank you!

1 Like