Failure to deploy on Node + MongoDB

Hi! So, I have had this environment with a Node app and a MongoDB database for at least a month or two with various successful deployments. Recently I have been running the app with local changes using qovery run from the CLI to query the DB and seed some data I’d need later, and only the other day I tried to deploy my changes remotely. While all my local tests were successful, the app seemed to crash near instantly after deploying and all further attempts to commit were met with failure

Issue:

All my recent attempts to deploy resulted on failure, with an error message, starting on

2021-06-05T22:19:22    DATABASE    ERROR    deployment error mongodb database gamedb : error => EngineError { cause: Internal, scope: Database("g54gshrsogo8b5ku", "MongoDB database", "gamedb"), execution_id: "81ce772ec723d5e1c879a8a63b60093084dd86c1ea454e08f3ae41bc2bf0d0b17f9e5970e9b80b27e6af2e248c8cc1f5b61ee94836d0b748a216915d6646ef5f", message: Some("MongoDB database service fails to be deployed (before start)") }

The output is too extensive (I have saved it into a file anyways), but the “Message for Qovery team” section was

    MESSAGE FOR QOVERY TEAM:
        * Execution ID     : 114d520290edbad44d4ae09c5886784e6ae458b8553f778fd70a07eebc60418af30cd2c569de02d8959a2b7efe8554c4a51768462f3f8e7b0fc7a550a86e771c
        * Scope            : MongoDB database Database 'gamedb' with id 'g54gshrsogo8b5ku'
        * Rollback message : 

To reproduce

  1. Perform write/read queries into a MongoDB instance using Mongoose in an Express.js server, locally, using qovery run in the CLI.
  2. Push the changes into the remote repo that Qovery reads from. A path should be left open in Express that will send in the response the output of a valid query.
  3. Access that aforementioned path.
  4. If there was an error, perform any action that would trigger a redeploy.
  5. Access the deployment logs. The failure will happen before the Node app runs.

Should be noted, while I don’t have a record of the original exception thrown by the query (I expected the error to be on my side and just pushed some code on my next commit that I hoped would clarify), all my subsequent attempts to deploy either to a newer, older, or same commit failed with a functionally identical error.

Expected behavior

A successful deployment, whether or not it throws any error in runtime.

you need to specify the DB path in qovery.yml

Hello,
as I can see in your logs, app can’t reach the db.

 Unauthorized: not authorized on admin to execute command

Isn’t it the issue ? All those logs came before db crash.

Thanks for the responses!

On both of them, wouldn’t that cause also trigger an error by manipulating the database in the qovery runcase? At least locally, I have been able to write into the database, and to later retrieve that information. The connection to it has been handled with environment variables, and at least I’m fairly confident I’m not running a local instance of MongoDB.

As for Kartik’s response, here is my qovery.yml,

---
application:
  name: "weird-space-game"
  project: "Weird Space Game"
  organization: "QoveryCommunity"
  publicly_accessible: true
  port: 8080
databases:
- type: "MONGODB"
  name: "gamedb"
  version: "3.6"
routers:
- name: "main-weird-space-game"
  routes:
  - application_name: "weird-space-game"
    paths:
    - "/*"

Could you please give me an example of where and how should I reference the path? Thanks!

Path is well referenced for me. I can see in your logs, you’re trying to reach 127.0.0.1 (network loopback). How do you set your db connection from the app ?

// DB init
const dbUrl = process.env.QOVERY_DATABASE_GAMEDB_CONNECTION_URI;
const dbCertificateUrl = "&ssl_ca_certs=db/rds-combined-ca-bundle.pem";
const dbOptions = {
    useNewUrlParser: true,
    useUnifiedTopology: true,
};

mongoose.connect(
    dbUrl,
    dbOptions
).then(
    () => {
        console.log("Successfully connected to the DB");
    },
    err => {
        console.log("Error in connection to the DB:" + err);
        console.log("Connection string is " + dbUrl);
    }
);

try using mongodb instead of MONGODB :sweat_smile:

May I do some test on your app ? If yes, please don’t restart or stop it.

By all means. I’ll hold off implementing that MONGODB → mongodb change until you’re done.

Thanks for all the help, seriously. I understand this may well be caused by a frankly embarrassing mistake on my part (I don’t have a lot of backend experience), but all the ideas help.

Usage of TLS to connect to MongoDB is mandatory.

Your Docker image must contain the TLS certificate of the MongoDB cluster - it can be downloaded here.

The application must be configured to use it. If you use the environment variable QOVERY_DATABASE_MY_MONGODB_CONNECTION_URI , you usually should have just append &ssl_ca_certs=/path/to/the/rds-combined-ca-bundle.pem to its value.

1 Like

So after few checks app & db are welled deployed. You got the fails status because something is trying to reach your db but fails each time (unauthorized operation).

Are you using some kind of socket or cron job ?

Nothing. The entire reason I wanted to manipulate the db locally was to be as sure as possible that the only point of contact between the db and everything else was through the Node app.

Are you trying to reach the database in an other way atm ? With some looped code or something like that. In logs I can see something is trying to do some stuff with db. Have any clue where it’s coming from ?

Nothing at all from my end. The only lines of code I wrote that so much as look in the general direction of the database are all in the Node app, and beyond the connection to it not being in a loop, I’m not running an instance of it and haven’t tried to do so for at least a day.

Ok. So I remember good old times when javascript was my world, I had to switch from mongoose from typeOrm because I had too many issues with this ODM. I’m not sure at all that is the problem but maybe you can give it a try.

The issue with something trying to reach the db is interesting and a bit concerning.

I’d be willing to look into replacing mongoose. That said, my first attempt to address that after your last message was to comment out all the code in the Node app that addressed the db, yet the issue persists. I think that whatever it is that’s trying to access the db is happening outside the app.