HabitRPG / habitica

A habit tracker app which treats your goals like a Role Playing Game.
https://habitica.com
Other
11.5k stars 4k forks source link

Mongo error on startup #15186

Open ploissken opened 1 month ago

ploissken commented 1 month ago

General Info

Description

I was following instructions here for starting the server on localhost. I never had mongo installed here before. Running npm run mongo:dev resulted in an error:

> habitica@5.22.0 mongo:dev
> run-rs -v 5.0.23 -h -l ubuntu1804 --keep --dbpath mongodb-data --number 1 --quiet

Skipping purge
Running '/Users/rs-producepay/Documents/habitica/node_modules/run-rs/5.0.23/mongod' [ 27017 ]
Restarting replica set...
Error: Server is unavailable
    at /Users/rs-producepay/Documents/habitica/node_modules/mongodb-topology-manager/lib/utils.js:79:40
    at Socket.<anonymous> (/Users/rs-producepay/Documents/habitica/node_modules/mongodb-topology-manager/lib/utils.js:43:5)
    at Socket.emit (node:events:513:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

I went googling around and found a workaround. Posting it here to raise awareness about the issue and also in case anyone runs into it.

  1. I've started changing the mongo:dev script in packages.json. I've added -h 127.0.0.1 to it, following a hint from this thread. The updated line in package.json now looks like this:

"mongo:dev": "run-rs -v 5.0.23 -h 127.0.0.1 -l ubuntu1804 --keep --dbpath mongodb-data --number 1 --quiet",

  1. Then I deleted all the files in /mongodb-data
  2. When I run the npm run mongo:dev again, the error is gone:
    
    > habitica@5.22.0 mongo:dev
    > run-rs -v 5.0.23 -h 127.0.0.1 -l ubuntu1804 --keep --dbpath mongodb-data --number 1 --quiet

Skipping purge Running '/Users/bodurico/Documents/habitica/node_modules/run-rs/5.0.23/mongod' [ 27017 ] Restarting replica set... Started replica set on "mongodb://127.0.0.1:27017?replicaSet=rs"

4. Then I hardcoded the mongo url above into the function `getDevelopmentConnectionUrl` in `website/server/libs/mongodb.js`. (Pretty nasty sorry)

return "mongodb://127.0.0.1:27017?replicaSet=rs";


5. `npm run start` went fine and no more troubles after that

habitica@5.22.0 start gulp nodemon

[17:24:10] Using gulpfile ~/Documents/habitica/gulpfile.js [17:24:10] Starting 'nodemon'... [17:24:10] Finished 'nodemon' after 13 ms [17:24:10] [nodemon] 2.0.22 [17:24:10] [nodemon] to restart at any time, enter rs [17:24:10] [nodemon] watching path(s): . [17:24:10] [nodemon] watching extensions: js,mjs,json [17:24:10] [nodemon] starting node ./website/server/index.js 2024-04-18T20:24:12.339Z - info Express server listening on port 3000 2024-04-18T20:24:12.347Z - info Connected with Mongoose.



I'll try to research deeper into this for a proper solution. Any hints would be appreciate!
CuriousMagpie commented 1 month ago

@SabreCat Can you take a look at this? Thanks!

diyoyo commented 1 month ago

@ploissken Never tried the regular install of Habitica (I want to make it work using docker), but I found out that the mongoose version 7.6.3 is messing things up when using mongo5 (again, this is my observation for docker containers)

I would suggest switching mongoose to 5.13.22 in package.json

diyoyo commented 1 month ago

@ploissken also, the Wiki (fandom) page seems outdated since Habitica 5.22 is supposed to run on Node20/Npm10.

CuriousMagpie commented 3 weeks ago

@diyoyo you are correct--we are running Node 20 and MongoDB 5.0.23 now. I'd recommend that @ploissken run npm ci to get a clean install of all the dependencies and try again--making changes to package.json and getDevelopmentConnectionUrl shouldn't be necessary!