Deploying feathersjs app with mongodb - mongodb

I am trying to deploy my feathersJS app on heroku with mongodb database. I used mLab sandbox plan, I did not configure anything on it. But as there is no documentation or any previous questions about it here I am.
I have made a feathersJS app running with mongodb. But when I deploy it on heroku I always get an error 503, service unavaible (timeout).
Here is in /config/default.json
"mongodb": "mongodb://localhost:27017/api_feathers",
There is may be something to change on this line.
And here production.js
{ "host": "api-feathers-app.feathersjs.com", "port": "PORT" }

As already pointed out you can add the MongoDB URL to your production.json in the mongodb property. Heroku will also set the MONGODB_URI for most MongoDB addons which you can use by changing production.json to::
{
"host": "api-feathers-app.feathersjs.com",
"port": "PORT",
"mongodb": "MONGODB_URI"
}

If you log into mlab and go to your database you should see a connection string. At the bottom of your production.json you should add a line to connect to the mlab database.
Something like:
{
"host": "api-feathers-app.feathersjs.com",
"port": "PORT",
"mongodb": "mongodb://USERNAME:PASSWORD#ADDRESS-AT-MLAB:PORT/DB_NAME"
}
That last line will be provided to you in the mlab settings. In addition mlab may require some query string at the end of the mongodb url, such as ?ssl=true. But they will tell you what is necessary.

Log in to your mlab account and create a new environment if not created already.
Then click on the database name. It will show you tab containing Collections, Users, Stats, Backups and Tools.
Click on the Users tab and it will show you a list of users assigned to that db. If you haven't created a user for that, then you will have to create a user by clicking on the "Add database user" button.
Once the user has been created you then add this to your production.json file. Add this as the value to the mongodb key in production.json file
mongodb://<dbuser>:<dbpassword>#ds115749.mlab.com:15749/<dbname>
replace the <dbuser> with the database username you created earlier and <dbpassword> the password associated to the dbuser and replace with the name of the database you are trying to access.
Here's a full code base for the production.json file
{
"host": "https://your.domainname.com/",
"port": "PORT",
"public": "../public/",
"paginate": {
"default": 10,
"max": 1000
},
"mongodb": "mongodb://<dbuser>:<dbpassword>#ds115749.mlab.com:15749/<dbname>",
}
Please note, default.json is for your development environment while production.json is for your production and used when you are deploying file in the same directory.

Related

Inserting data to MongoDB Atlas using Mongoose and SRV connection string

I have created a cluster in MongoDB Atlas and can't seem to be able to write data to it.
const uri = "mongodb+srv://myUser:myPass#myDB-4myav.mongodb.net/portfolio";
I have this as my uri to connect to, and every time I try to write to the database, I get this error:
{ MongoError: not authorized on admin to execute command { insert:
"users", documents: [[{name Daniel} {_id
ObjectIdHex("5aa6d7d6396deb25844ccb52")} {__v 0}]], ordered: false }
I have read that I need to create an admin user with the role of "root" but when I connect to my database using the mongo shell and try creating it, I get this:
Error: couldn't add user: not authorized on admin to execute command
So basically I don't have a user that can write to my database.
I've also tried making a user with every role possible on the MongoDB Atlas website (for my cluster of course) and then connecting through the mongo shell with it, but that failed as well.
To summarize: I've made a new cluster on MongoDB Atlas. How do I write data to it?
Thanks in advance, feel free to point out if I'm missing something simple and stupid.
{ MongoError: not authorized on admin to execute command { insert: "users", documents: [[{name Daniel} {_id ObjectIdHex("5aa6d7d6396deb25844ccb52")} {__v 0}]], ordered: false }
This error indicates your code is trying to insert documents into the admin database, which is a system database reserved for user and role information.
In your connection string you intended to use the portfolio database. However, the srv connection string format does not support specifying a database so your option was ignored and the default database of admin was used. You need to select the portfolio database after connecting.
This was also reported in the Mongoose issue tracker (GitHub issue #6106) where a user posted a workaround you could adapt:
mongoose.connection.on('connected', function() {
// Hack the database back to the right one, because when using mongodb+srv as protocol.
if (mongoose.connection.client.s.url.startsWith('mongodb+srv')) {
mongoose.connection.db = mongoose.connection.client.db('portfolio');
}
console.log('Connection to MongoDB established.')
});
mongoose.connect(...);
I have read that I need to create an admin user with the role of "root" but when I connect to my database using the mongo shell and try creating it, I get this:
You need to manage users via MongoDB Atlas rather than the mongo shell. You can create a user account with the "Read and write to any database" role (or more refined privileges using Advanced Options).
You need to create a user with root role from Mongo Shell,
use admin
db.createUser(
{
user: "admin",
pwd: "password",
roles: [ { role: "root", db: "admin" } ]
}
);
exit;
or you need to add new user through atlas(refer below snapshot)
Goto Clusters
click Security
Click ADD NEW USER
type username
create Password based on SCRAM-SHA1 method
choose ROLE Atlas admin
click Add User
After created user, goto Clusters-->OverView --> CONNECT
Verify the IP Whitelist
Choose a connection method:
Connect with Mongo Shell (I am choosing)
Connect your Application
Connect with MongoDB Compass
$ mongo "mongodb+srv://project-u-s3cgp.azure.mongodb.net/test" --username dbAdmin
MongoDB shell version v3.6.1
Enter password:
connecting to: mongodb+srv://project-u-s3cgp.azure.mongodb.net/test
.........
.........
MongoDB Enterprise project-U-shard-0:PRIMARY>db.user.insert({name:"Daniel"})
WriteResult({ "nInserted" : 1 })
MongoDB Enterprise O2Ci-U-shard-0:PRIMARY>
I hope, you can able to insert the record after creation of root user.
Thanks,
Karthick

Azure Data Factory AWS PostgreSQL RDS as source connection

I am attempting to use an AWS PostgreSQL RDS instance as my source for a data factory pipeline. I am unable to get this connection to work in ADF v1 or v2. I have tried everything from using a PostgreSQL connection to an Azure database for PostgreSQL. Essentially I am going cloud to cloud, and this connection doesn't seem to be supported yet. Has anyone else had any luck doing this?
yes, this is horribly broken as you have found out. Two main problems:
1) You must install the NpgSQL 2.0.14.3. driver (chose core installation option to ensure both x86 and x64 versions are installed) this version won't validate the server certificate
2) PostgreSQL connector can only enter connection information using by uploading via PowerShell the current GUI does not support the full configuration of the data source:
Here is the example json:
{
"name": "PostgreSqlLinkedService",
"properties": {
"type": "PostgreSql",
"typeProperties": {
"server": "<server>",
"database": "<database>",
"username": "<username>",
"password": {
"type": "SecureString",
"value": "<password>"
}
},
"connectVia": {
"referenceName": "<name of Integration Runtime>",
"type": "IntegrationRuntimeReference"
}
}
}
alternatively, the ODBC driver can work around this issue as you need to specify additional properties on the connection string that are not exposed by the pg connector. you need to add the following value to the DSN:
**sslmode=Require;Trust Server Certificate=true*
and that should resolve the error
note: the ODBC nor the Postgresql Connector's currently work with the ADF v2 Lookup activity.

db.serverStatus() returns "not authorized to execute command" on mlab w/ owner privileges

I recently opened up a free mLab account, and I'm trying to access the number of open connections in my database through the shell.
I never had problems with the command line when I was running mongodb locally, but now nothing works.
To connect I do this:
mongo ds127044.mlab.com:27044/db_name -u db_user -p db_password
And it show I'm successfully connected.
After that I run:
db.serverStatus()
And get:
{
"ok" : 0,
"errmsg" : "not authorized on admin to execute command { serverStatus: 1.0 }",
"code" : 13,
"codeName" : "Unauthorized"
}
But according to my console I'm listed as the owner of the db:
{
"_id": "db_name.db_user",
"user": "db_user",
"db": "db_name",
"roles": [
{
"role": "dbOwner",
"db": "db_name"
}
]
}
Is there something I'm doing wrong in the command line or is it something particular to my account with mLab?
Seems to be something related with your user's roles.
All documentation here: https://docs.mongodb.com/manual/reference/built-in-roles/#cluster-admin-roles/ (specifically cluesterMonitor information)
Say:
...The admin database includes the following roles for administering the
whole system rather than just a single database...
And in this Doc https://docs.mongodb.com/manual/core/security-built-in-roles/
Say:
Every database includes: Database Administration Roles... The
admin database includes the following roles for administering the
whole system: Cluster Administration Roles
'serverStatus' is realted to clusterMonitor role so..
Try to change it:
roles: [ { role: "clusterMonitor", db: "admin" },
{ role: "dbOwner", db: "db_name" }]
Good luck!
Not a mongodb expert, but here's what I found in the docs.
db.serverStatus() shares instance info in its output. For example:
host
The system’s hostname. In Unix/Linux systems, this should be the same as the output of the hostname command.
mLab wouldn't expose host info to end users, who should only have access to the dbs they're creating--specifically, the db you logged into.
Similarly, you'll run into issues with other calls like show dbs, since that would expose all the dbs (including dbs for other users!) existing alongside your own.
I imagine that the only commands that will work are ones that expose info completely related to only your db. I suggest hitting up a more export mongodb admin perhaps in a separate question for that definitive list, if necessary.
I fixed this exact issue by changing my mac settings to allow remote login.
System Preferences -> Sharing -> Remote Login: On

What is the way to connect ClearDb Mysql dashboard on Bluemix?

I created a ClearDb Mysql database on Bluemix. I got all the data to conect it but i can't do it.
I tried to use Squirrel and i always got a timeout connection.
So i wanted to use the web interface but it asks me a login/password because the area seems restricted.
I got this message on popup :
A username and password are being requested by https://bluemix-eu-gb.marketplace.ibmcloud.com. The site says: "Restricted Site"
I tried to feed the fields with the data found to connect the db : it's failed. I also tried the login/password for Bluemix : failed too...
I tried many other things but the good one.
Maybe i missed something when i created the DB or ... i don't know.
If anyone could give me the (obvious?) trick?
I used SQuirrel and it works fine for me to connect to the ClearDB MySQL database instance.
Here are the steps I followed:
1) Bound your ClearDB MySQL instance to an application (this is step is only needed so you can find your database credentials)
2) In the Bluemix UI select the application you created above, this will open the application dashboard
3) Locate the ClearDB MySQL instance tile and select the "Show Credentials" at the bottom of the tile. You should something similar to this (for privacy I changed ids and password below):
{
"cleardb": [
{
"name": "ClearDB MySQL Database-29",
"label": "cleardb",
"plan": "spark",
"credentials": {
"jdbcUrl": "jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/DATABASENAME?user=USERNAME&password=PASSWORD",
"uri": "mysql://USERNAME:PASSWORD#us-cdbr-iron-east-04.cleardb.net:3306/DATABASENAME?reconnect=true",
"name": "DATABASENAME",
"hostname": "us-cdbr-iron-east-04.cleardb.net",
"port": "3306",
"username": "USERNAME",
"password": "PASSWORD"
}
}
]
}
4) Create the alias in SQuirrel and use the values above in the fields, please note that your server name could be different than mine:
Name: MyAliasName
Driver: MySQL Driver
URL: jdbc:mysql://us-cdbr-iron-east-04.cleardb.net:3306/DATABASENAME
User Name: USERNAME
Password: PASSWORD
5) Click Test button to check your connection. Everything should be fine.

Node.js - Connecting to MongoDB using MongoHQ on Heroku

I have a Node.js app using Express that stores data in a mongoDB (locally).
It's now pushed to heroku successfully on a cedar stack and the server is running. I added the mongohq addon through the terminal.
Now... how do I connect that mongoDB through mongohq to my application to start using it??? I don't see a tutorial for this anywhere online. If you can point me to one or get me started on where to add the configuration, I would greatly appreciate!
Thanks much.
Update:
I've tried the following (with real values for MYPASSWORD and MYDBNUMBER:
in routes.js
var db = mongoose.connect('mongodb://heroku:<MYPASSWORD>#staff.mongohq.com:10049/<MYDBNUMBER>');
in my schema.js (also tried using the heroku
var mongoose = require('mongoose');
mongoose.connect('mongodb://heroku:<MYPASSWORD>#staff.mongohq.com:10049/<MYDBNUMBER>');
my package.json
{
"name": "NAME"
, "version": "0.0.1"
, "dependencies": {
"express": "2.4.6"
, "connect": "1.7.1"
, "stylus": ">= 0.0.1"
, "mongodb": ">= 0.9.6-7"
, "mongoose": ">= 2.0.0"
, "ejs": ">=0.4.3"
}
}
Right now, only the root '/' GET is successful. Actually, if I try /page/ANYTHING I can successfully get a rendered 500 Error page that I made to handle attempts to get 'pages' that haven't been created... That seems kind of weird to me. Everything else gives me an Internal Server Error.
ALSO, if i go to mongohq and open my database there, a collection for my model pages has been created and the indexes for uniqueness have been created, even tho I haven't been able to access the pages to create or view the model in my app...
happy to provide any other info... so stuck.
We are using heroku against MongoHQ but in our case we created the MongoHQ account on our own so our solution is a bit different.
Now, we are using the Redis plugin and in that case we connect to Redis using the heroku env variables.
When you create a new plugin, Heroku adds a bunch of env variables that you can access from your node.js app easily doing this:
process.env.NAME_OF_VAR
In the case of Redis to go the name of the var is REDISTOGO_URL so our code looks like
process.env.REDISTOGO_URL
For MongoHQ the env variable seems to be MONGOHQ_URL
You may need to do some parsing. Heroku have some documentation for Ruby here http://devcenter.heroku.com/articles/mongohq#using_the_mongo_ruby_driver that should help you to get it going.
With respect to where to do this in an express app. We are doing all the setup on app.js that is our entry point in the app.
Hope this helps.