upgrade MongoHQ prevents sails-mongo to connect in prod env - mongodb

I am using SailsJS 0.10.5.
I purchased a production MongoDB from Heroku and it created a variable with the new database url as follows:
mongodb://heroku:**password**#candidate.32.mongolayer.com:10485,candidate.13.mongolayer.com:10455/app123
However, when running the app in production environment only, the app fails to connect to database:
A hook (`session`) failed to load!
Could not load Connect session adapter :: connect-mongo
at new MongoStore (/app/node_modules/connect-mongo/lib/connect-mongo.js:115:19)
at validateDatabaseName (/app/node_modules/connect-mongo/node_modules/mongodb/lib
/mongodb/db.js:235:59)
at Hook.Session.initialize (/app/node_modules/sails/lib/hooks/session/index.js:20
5:37)
Error from adapter:
Error: database names cannot contain the character '.'
at new Db (/app/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js
Note that when I copied the string locally and ran the app it worked perfectly.
I saw some workarounds suggest using Mongoose, but I want to stick to connect-mongo / sails-mongo
EDITED
I now managed to connect to the db by removing the replica set and simply add:
mongodb://heroku:**password**#candidate.32.mongolayer.com:10485/app123
However, a new error arrived:
Error: Error setting TTL index on collection : sessions
throw message;
at /app/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:700
at commandHandler (/app/node_modules/connect-mongo/node_modules/mongodb/lib/mongo
at Cursor.close (/app/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb
at /app/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1882:9
at Server.Base._callHandler (/app/node_modules/connect-mongo/node_modules/mongodb
at /app/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/connection/se
It keeps crashing the app.
Ideas?

Try to setup and download mongo-uri to parse the url automatically

Related

Prisma DB Can't connect to AWS RDS

I have a nextjs project that's using prismaDB for the ORM. I'm able to connect just fine to my local postgres db but I'm getting this error when running npx prisma migrate.
Error: P1001: Can't reach database server at db-name.*.us-west-2.rds.amazonaws.com:5432.
schema.prisma:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
//url = "postgresql://master_username:master_password#aws_host:5432/db_name"
}
The RDS db is currently public and I'm positive that I've copied over the RDS credentials correctly. There doesn't seem to be anything I should be including for the connection to work but I'm not getting any other info as to why I can't reach the db server.
Seems like you have to replace db-name.*.us-west-2.rds.amazonaws.com with the name of your actual database, unless you replaced it for the purpose of asking this question. Specifically the part where it says db-name.*.
Docs: https://www.prisma.io/docs/reference/api-reference/error-reference#common
P1001 indicates that it couldn't find the database given the connection string, NOT necessarily that the credentials you provided were wrong. Make sure you're specifying the correct database name/host and whatever else you need to make it work for AWS.
Somehow I was able to connect to RDS after deleting and creating a new DB for the third time. I confirmed connection through pgAdmin then tried it again my app deployed to vercel.

Error in connector: missing field `info` - Prisma Introspection (npx prisma db pull)

I have created an Express, Apollo GraphQL server which accepts requests and returns data from a MongoDB database via Prisma.
I have tested my application with a simple database from MongoDB Atlas and it all seems to work fine.
Now that I know everything works fine, I want to 'plug in' a MongoDB database which contains a lot of data already, located in my Azure portal (Cosmos DB).
I have changed the database connection string to point to this new database (a read only connection string) and now attempting to use the Introspection feature of Prisma (https://www.prisma.io/docs/getting-started/setup-prisma/add-to-existing-project/mongodb/introspection-typescript-mongodb#introspecting-mongodb-with-prisma).
After running the npx prisma db pull --force command, I get the following error:
I can't figure out if this is an issue with my connection string, or something else.
I have also attempted to use the Read/ Write connection string but that doesn't seem to work either. I get the same error message.
There does not seem to be any information online regarding this error message other than this:
https://www.prisma.io/docs/reference/api-reference/error-reference#prismaclientvalidationerror
But I am unsure if this is at all related, because it seems to relate to creating a new record, rather than anything to do with introspection.

Not able to make postgres database call on heroku using Play Framework Application

I am build REST api using play framework 2.8 , I am able to start the application and call some service. Facing issue when trying to connecting with postgres database. Logs are below -
Error opening connection for database: {}org.postgresql.util.PSQLException: FATAL: no pg_hba.conf entry for host "3.87.112.32", user "abc", database "xyz", SSL off
Tried looking solution for this and foudn have to add sslmode=require in query param while connection to database.
When log the url sslmode is already mentioned.
jdbc:postgresql://abc.amazonaws.com:5432/xyz?password=1234&sslmode=require&user=xyz
I am reading this property from heroku env variable JDBC_DATABASE_URL for obtaining database connection.
This issue can be fixed by adding addition query parameters apart from sslmode=require which are ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory after adding this the new URL become jdbc:postgresql://abc.amazonaws.com:5432/xyz?password=1234&sslmode=require&user=xyzssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory

Sails.js default app fails to start with MongoDb

I created a WebApp with sails new my-app and am trying to use mongodb as its database. I am running mongodb in docker and am able to connect to the database using GUI tools like MongoDB Compass. Using that tool I created todo_list database in mongo.
In the app, I changed default datastore in datastores.js to:
default: {
adapter: 'sails-mongo',
url: 'mongodb://root:rootpassword#localhost:27017/todo_list'
}
This connection string is correct as verified by using it to connect via MongoBD Compass.
When I run sails lift I get:
error: A hook (`orm`) failed to load!
error: Could not tear down the ORM hook. Error details: Error: Consistency violation: Attempting to tear down a datastore (`default`) which is not currently registered with this adapter. This is usually due to a race condition in userland code (e.g. attempting to tear down the same ORM instance more than once), or it could be due to a bug in this adapter. (If you get stumped, reach out at http://sailsjs.com/support.)
I saw this error raised in a few github issues, bu tteh answers were irrelevant to my situation. Any ideas what I could be doing wrong?

Cannot connect to Heroku MongoDB

I created an Ionic app with NodeJS backend and Mongo database and deployed it to Heroku (with mLab MongoDB add-on). It worked well for a day. The next day I was unable to connect to the DB. The app went to sleep in the meantime, but when I opened it in the browser it woke up. I know that because I saw the static text that I put on the index page. But a few seconds later, an error page appeared. From the console and network tabs output I could figure out that the app is unable to access the database and to fetch data.
I found a post on the internet where the author said that he had the same issue and that he deleted the db instance on Heroku and created a new one. So I did the same and then I was able to start my app normally again.
Today the same thing happened - I can't connect. When I switch the DB URI in the code to mongodb://localhost/mydbname and run the application locally, it works perfectly, so I concluded that the app code itself is fine, there's only an issue with connecting to the DB. It also wouldn't work locally if I try to target the DB on Heroku.
I thought that I might forgot the credentials, so I went to the Heroku dashboard and changed both the username and the password. Then I tried to connect through the console with mongo ds<number>.mlab.com:<port>/heroku_<name> -u <username> -p <password>. Here's the output:
MongoDB shell version v3.6.3
connecting to: mongodb://ds213239.mlab.com:13239/heroku_d3xjtj3x
2018-03-16T16:09:18.215+0100 W NETWORK [thread1] Failed to connect to 54.236.230.76:13239 after 5000ms milliseconds, giving up.
2018-03-16T16:09:18.216+0100 E QUERY [thread1] Error: couldn't connect to server ds213239.mlab.com:13239, connection attempt failed :
connect#src/mongo/shell/mongo.js:251:13
#(connect):1:6
exception: connect failed
Currently I'm using free version of both hosting and DB add-on, because I want only to test the app and to show it to my client (who will then decide if he wants to pay for the Heroku services). If I have nothing to show and if this happens each time, well, that would suck.
And here's the fun part: I wanted to try to open the app one more time so that I could copy and paste the exact error message here. And this time it worked normally! (???) The only thing I did is that I changed the username and pass on the DB dashboard, but I didn't push the updated code and I also didn't change it in the MONGODB_URI config variable.
Does anyone have an idea why does this happen? Is there a way to keep the DB awake and accessible (without paying extra)?
Thanks.
EDIT: It doesn't work again!!! Literally 30 seconds after submitting this post I tried to access the app again and it didn't work! There is an error page which says:
Error: Uncaught (in promise): [object Object]
at c (http://localhost:8100/build/polyfills.js:3:19752)
at c (http://localhost:8100/build/polyfills.js:3:19461)
at http://localhost:8100/build/polyfills.js:3:20233
at t.invokeTask (http://localhost:8100/build/polyfills.js:3:15660)
at Object.onInvokeTask (http://localhost:8100/build/vendor.js:4973:33)
at t.invokeTask (http://localhost:8100/build/polyfills.js:3:15581)
at r.runTask (http://localhost:8100/build/polyfills.js:3:10834)
at o (http://localhost:8100/build/polyfills.js:3:7894)
at e.invokeTask [as invoke] (http://localhost:8100/build/polyfills.js:3:16823)
at p (http://localhost:8100/build/polyfills.js:2:27648)
ONE MORE EDIT: I deleted the DB again, created a new one, changed the connection string in my app and pushed the changes. Now it works normally. I'll check again tomorrow and update this post.
NEW EDIT: One day later, the app doesn't connect to the DB again. And again I get the same error message.
Wtf, Heroku???