dokku / dokku-mongo

a mongo plugin for dokku
MIT License
174 stars 32 forks source link

Replica Set needed #190

Closed kamzata closed 5 months ago

kamzata commented 1 year ago

I wrote a simple todo app using NextJS and I used MongoDB and Prisma as ORM.

The issue is Prisma complains MongoDB needs to be configured as Replica Set as written here.

How can I configure MongoDB plugin in order to make it works?

I already checked this but it didn't work.

Locally I successfully done this and it worked.

josegonzalez commented 1 year ago

This isn't a feature supported out of the box by this plugin. Others may have gotten it working, but it's not something I planned on supporting. If you'd like to sponsor this feature, please let me know.

kamzata commented 1 year ago

This isn't a feature supported out of the box by this plugin. Others may have gotten it working, but it's not something I planned on supporting. If you'd like to sponsor this feature, please let me know.

Thanks, I will sponsor for sure. I just don't understand the usefulness of this plugin without this (I think) basic feature. Is there a way to use it with Prisma or Mongoose without Replica Set? How?

kamzata commented 1 year ago

However, I think I successfully converted mongod Standalone to a Replica Set but my app still not work.

I took this steps:

As I said, now it seems to run as Replica Set but the app still doesn't work.

I checked the logs running:

dokku  mongo:logs $YOUR_SERVICE -t

but there's no output whenever I try to communicate from the app in order to read or write on the db.

I tried to reboot everything and unlink and link again the mongodb service to the app but without success.

josegonzalez commented 1 year ago

I just don't understand the usefulness of this plugin without this (I think) basic feature

MongoDB Replica sets are usually used for high availability and clustering, two things that aren't goals for these plugins (no one has sponsored or contributed this sort of functionality in the 8 years this plugin has been around). I don't know why it doesn't work with Prisma either - we've had other users that have used Prisma just fine.

I'll keep this ticket open but I will say I don't have free personal time to spend on this so I likely won't be working on this. If others figure out how to get it running, I'd be more than happy to take a pull request (for docs or functionality).

kamzata commented 1 year ago

I just don't understand the usefulness of this plugin without this (I think) basic feature

MongoDB Replica sets are usually used for high availability and clustering, two things that aren't goals for these plugins (no one has sponsored or contributed this sort of functionality in the 8 years this plugin has been around). I don't know why it doesn't work with Prisma either - we've had other users that have used Prisma just fine.

I'll keep this ticket open but I will say I don't have free personal time to spend on this so I likely won't be working on this. If others figure out how to get it running, I'd be more than happy to take a pull request (for docs or functionality).

It needs Replica Sets because MongoDB database connector uses transactions to support nested writes and transactions require a replica set deployment.

However, even tough I was able to convert it to a Replica Set, I'm not still able to query the database.

In my app I'm using this schema file:

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "mongodb"
  // String connection passed here without using a env file just for test purpose
  url      = "mongodb://todo-test-db:51605620d3aa408d19c3a69692743e6b@dokku-mongo-todo-test-db:27017/todo_test_db"
}

model Todo {
  id          String   @map("_id") @id @default(auto()) @db.ObjectId
  title       String
  isCompleted Boolean              @default(false)
  createdAt   DateTime             @default(now())
  updateAt    DateTime             @updatedAt
}
kamzata commented 1 year ago

I eventually made it works. There were some entries in the collection formatted wrong. After clean the collection (db.$collection.deleteMany({})) it worked straight away. So, as far as I can see, the above procedure to convert MongoDB Standalone to a Replica Set is correct. Thanks.

josegonzalez commented 5 months ago

Closing this ticket. I don't plan on adding support in these plugins for clustering, but if folks want to PR it, that would be fine.