Unable to connect to mLab database from self-hosted Parse - mongodb

TL;DR: I can get my parse dashboard talking to my locally-hosted Parse server and mongo db instance but cannot get the parse server to talk to the mLab-hosted database.
I am going through the Parse migration guide and have got mongo DB, parse-server-example and parse-dashboard running locally. When I use the following details in the parse index.js file I can successfully connect the dashboard and see the test items in the database:
databaseURI: 'mongodb://localhost:27017/dev',
cloud: __dirname + '/cloud/main.js',
appId: '1',
masterKey: '1',
serverURL: 'http://localhost:1337/parse'
I have installed mongo db locally and when connecting to my mLab instance with the shell I can see the database content. When I use that same mLab connection string in the databaseURI parameter within index.js the dashboard can no longer see the database content and the /test page on the locally-hosted parse server.
The Parse Migration Guide states...
Go to the Security & Keys section of App Settings in your Dashboard
and take note of the File Key and Master Key values. Pass that into
the ParseServer constructor in index.js. You no longer need to use a
client key with Parse Server.
I can find those keys but I cannot see where to put the File Key into the index.js.
I also do not understand why those keys are required if the locally-hosted Parse server and mLab database know nothing about them.

steps :
create your user/pwd in the mLab/mongo instance
get the db URL from mLab dashboard
connect using a command lib client to verify what parse-server will
use. this verifies the user/pwd you will use below...
go back to 'parse-server.js' to config it for mongo/remote
var databaseUri = $what-was-on-cli-client-above
var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://<db.....
....

Related

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.

PostgreSQL setup in Sails

I am new to sails and its connection to database. I plan to use Heroku to host my app so I would like to use Postgresql.
I have changed config.datastore file with the following code:
default: {
adapter: 'sails-postgresql',
url: 'postgresql://postgres:postgres#localhost:5432/postgres',
max: 1
}
On Sails documentation it sais that url is url: 'postgresql://user:password#host:port/database', but I dont understand where should I get user and password from. Do I need to initiate the postgresql and set it up and define a new database?
I am just trying to understand the mechanics behind this setup.
What you need to do is create a new user for your local PostgreSQL instead of using the default user and database. What I mean is, create a user-specific to your particular project in SQL following this should help https://www.postgresql.org/docs/8.0/sql-createuser.html.(This should also help you set the password)
Then create the database you want to connect to your Sails app to be used by Waterline by following this: https://www.postgresql.org/docs/9.0/sql-createdatabase.html (make sure you grant the user you created permissions for this database as well https://www.postgresql.org/docs/9.0/sql-grant.html)
Then all you need is replace the url property value in config/datastore.js with the value following the format
postgres://USERNAME:PASSWORD#localhost:5432/DATABASE_NAME
N.B: Replace USERNAME, PASSWORD, and DATABASE_NAME with the actual username, password, and database name respectively.
When you are deploying to Heroku, Heroku would provide you with an environment variable called DATABASE_URL if you install the Heroku Postgres add-on. You could just pass that to url like so
url: process.env.DATABASE_URL

setting up graphQL on OpenShift

I'm learning how to set up a server on OpenShift that uses node, express, GraphQL and Postgres and I need some help.
When trying to set up the GraphQL Server I've been following this and it works on my local machine:
import Express from 'express';
import GraphQL from 'express-graphql';
import Schema from './db/GQLschema';
const app = Express();
app.use('/graphql', GraphQL({
schema: Schema,
pretty: true,
graphiql: true
}));
...
I'm using the server.js template provided by OpenShift so the above changes to:
...
self.app = express();
self.app.configure(function() {
self.app.use('/public', express.static(__dirname+'/public'));
self.app.use('/graphql', GraphQL({
schema: Schema,
pretty: true,
graphiql: true
}));
});
...
But this doesn't work when pushed up to OpenShift. I get 'Internal Server Error' instead of the graphiql interface.
I'm new to this, but here are some guesses as to what it might have to do with:
Connecting to database
Missing dependencies
Connecting to database: I have 2 json config files. One for my local machine which is connected using a port-forward SSH tunnel to OpenShift. That works fine. The other is one for production. In it I have all the strings for the database name, user, port, host, and password, that OpenShift provided me. I'm using the config library which looks at NODE_ENV to decide which config json file to use. I set the NODE_ENV variable on OpenShift to production. When I query it, it shows all the correct strings. Is there something else I need to set?
Missing dependencies: To keep it neat, I am keeping my back-end code separate from my front-end code. So the back-end code has only the express, graphql, sequelize, config, and pg stuff installed. Do I need something else to make the graphiql page work? Also, I put all the /node_modules/ in the .gitignore file -- I assumed that OpenShift installs them post push. Was that the right thing to do?
Would appreciate any help!
OK - I solved it by doing the following:
in the openshift cli tools turn on error logs
rhc tail -a <yourappname>
This will give you some clues. In my case it was a message from express-graphql "unresolved promise". After researching I found that if you install and save es-promise and add this line to the top of the server.js file:
require ('es6-promise').polyfill();
Hope that helps someone else!

Parse.com connecting MongoLab URI to Parse Dashboard

I have trouble connecting my mongodb database to Parse Dashboard using the required URI :
mongodb://user:password#dsXXXXX.mongolab.com:XXXXX/my_db?ssl=true
Here is what I get :
I'm completely new to mongdb and mongolab and cannot figure out what's going on.
I using Heroku and MongoLab for Parse,
And the URI I am using, I've got from Heroku app setting page as follows:

upgrade MongoHQ prevents sails-mongo to connect in prod env

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