dokku/dokku-mongo

Replica Set needed

kamzata opened this issue · 7 comments

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.

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.

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?

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

I took this steps:

  • edited config options: sudo nano /var/lib/dokku/services/mongo/$YOUR_SERVICE/CONFIG_OPTIONS
  • change its content to this --keyFile /data/db/keyfile --replSet rs0 --storageEngine wiredTiger --auth
  • created a key file: openssl rand -base64 756 > keyfile
  • then: chmod 400 keyfile
  • then: mv keyfile /var/lib/dokku/services/mongo/$YOUR_SERVICE/data/
  • then removed the container: sudo docker rm -f dokku.mongo.$YOUR_SERVICE
  • then started again: dokku mongo:start $YOUR_SERVICE
  • then connected to the mongodb instance: dokku mongo:connect-admin $YOUR_SERVICE
  • then this:
use admin
rs.initiate()
use local
db.system.replset.find()
exit
  • then: dokku mongodb:restart $YOUR_SERVICE
  • connected again to the instance: dokku mongo:connect-admin $YOUR_SERVICE
  • and check if it's running as Replica Set: rs.status()

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.

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).

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
}

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.

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.