Remote MongoDB access through Cloud 9 gives login failed exception - mongodb

I'm using the Cloud 9 IDE to develop an application using MongoDB. I created a database called "appdata" at MongoLab and the following user:
{
"_id": "appdata.admin",
"user": "admin",
"db": "appdata",
"credentials": {
"SCRAM-SHA-1": {
"iterationCount": 10000,
"salt": "K/WUzUDbi3Ip4Vy59gNV7g==",
"storedKey": "9ow35+PtcOOhfuhY7Dtk7KnfYsM=",
"serverKey": "YfsOlFx1uvmP+VaBundvmVGW+3k="
}
},
"roles": [
{
"role": "dbOwner",
"db": "appdata"
}
]
}
Whenever I try connecting to the database through Cloud 9 Shell using the following command (given by MongoLab with my newly created user):
mongo ds057244.mongolab.com:57244/appdata -u admin -p admin
I get the following error message:
MongoDB shell version: 2.6.11
connecting to: ds057244.mongolab.com:57244/appdata
2015-11-22T05:23:49.015+0000 Error: 18 { ok: 0.0, errmsg: "auth failed",
code: 18 } at src/mongo/shell/db.js:1292
exception: login failed
Also, on my javascript file running on Cloud 9, while following this tutorial (which uses mongoose to access the DB) I got stuck on the post route for bears. Whenever I send a post request through postman with the specified fields set, the route doesn't return anything, neither a bear created nor an error message, which makes me think the problem is also failing to login to the database. The previous get request is working just fine and my code is the exactly same as the tutorial.
Does anyone know what the problem in any of the cases and what I need to do to solve them?

The shell problem was fixed updating it to the Database version (which was 3.0.3).
For the javascript files, I restarted the tutorial and made sure I downloaded all necessary dependencies with the most recent stable version (not the ones shown on the tutorial), after that the problem was solved.

Related

MongoDB Compass throws authorization error but in-app console works

I'm trying to connect to a DocumentDB instance using MongoDB Compass. I'm not using root user but a user with read/write access to one specific database only. I'm specifying the authSource and specifying in the URI the database to connect to. When I connect I get a "Authorization Failure" error:
But the in-app mongosh console works just fine:
If I type and delete in the searchbox, the database and collection appears in the GUI, but when I try to access any of them, it does nothing and in the developer console the following error is thrown:
Uncaught (in promise) TypeError: Invalid Version: undefined
at new W (374.b19c47bda474faa622ac.renderer.js:2)
at K (374.b19c47bda474faa622ac.renderer.js:2)
at Function.ee [as gte] (374.b19c47bda474faa622ac.renderer.js:2)
at i (index-4d5b3902.00103f1fccf1df6cf12c.renderer.js:1)
at Object.Ye [as configureStore] (index-4d5b3902.00103f1fccf1df6cf12c.renderer.js:1)
at f (index-7aeafcb2.6cd34d3932bd058955c3.renderer.js:1)
at index-7aeafcb2.6cd34d3932bd058955c3.renderer.js:1
at Array.forEach (<anonymous>)
at b (index-7aeafcb2.6cd34d3932bd058955c3.renderer.js:1)
at index-7aeafcb2.6cd34d3932bd058955c3.renderer.js:1
In the MongoDB Compass logs the only error I can see is:
{
"msg": "Driver command failed",
"attr": {
"address": "xxxxxxx:27017",
"serverConnectionId": 1,
"duration": 215,
"commandName": "getParameter",
"failure": "Feature not supported: getParameter"
}
}
Is this some kind of MongoDB Compass bug? Is it an incompatibility between Compass and DocumentDB? Or may it be something related to permissions added to the user role I'm trying to authenticate with?
Thanks all.
Check this page: https://www.mongodb.com/docs/compass/current/connect/required-access/
I believe you'll need the clusterMonitor role for the restricted user you're using.

Hostname resolving error in Stepzen Graphiql explorer when connecting with Supabase Postgresql database

I have set up Stepzen as described in the Getting Started Docs. I get the following error when running stepzen start:
{
"data": {
"getProfilesList": null
},
"errors": [
{
"message": "database error: can't prepare the statement for execution failed to connect to `host=postgres user=root database=`: hostname resolving error (lookup postgres on 10.97.0.10:53: no such host)",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"getProfilesList"
]
}
]
}
The message shows wrong hostname, user and empty database, although my config file has the correct credentials:
configurationset:
- configuration:
name: postgresql_config
uri: postgresql://postgres:[My Password]#[My Supabase DB Host]/postgres
I have also tried to connect to the DB directly from a GUI client and the connection was successful.
Why this issue is coming up when trying to connect from Stepzen Graphiql explorer running on localhost?
Postgres requires the password to be URL Encoded when using some characters that have a special meaning.
You can learn more about percent-encoding to handle special characters in Postgres passwords here: How to handle special characters in the password of a Postgresql URL connection string?

Strange error when initializing Postgres database in FeathersJS

I am converting a FeathersJS system from MySQL to Postgres and facing some problems.
After changing the connection string
"mysql": "mysql://user:password#server:port/database"
to
"postgres": "postgres://user:password#server:port/database"
at config/default.json, I changed the dialect from mysql to pg at feathers/sequelize.js.
But when I started with npm run dev I got the following JSON error message, never seen before.
{
"_bitField":18087936,
"_fulfillmentHandler0":{
"name":"SequelizeConnectionError",
"parent":{
"name":"error",
"length":93,
"severity":"FATAL",
"code":"3D000",
"file":"postinit.c",
"line":"855",
"routine":"InitPostgres"
},
"original":{
"name":"error",
"length":93,
"severity":"FATAL",
"code":"3D000",
"file":"postinit.c",
"line":"855",
"routine":"InitPostgres"
}
},
"name":"SequelizeConnectionError",
"parent":{
"name":"error",
"length":93,
"severity":"FATAL",
"code":"3D000",
"file":"postinit.c",
"line":"855",
"routine":"InitPostgres"
},
"original":{
"name":"error",
"length":93,
"severity":"FATAL",
"code":"3D000",
"file":"postinit.c",
"line":"855",
"routine":"InitPostgres"
}
}
After researching a bit with no success, here I am to ask if someone has ever seen this message.
I already tried the dialect as pg and postgres at feathers/sequelize.js, just to check if it would make any difference, but it didn't.
A true beginner error! My fault!
When I created the Postgres (Docker) container, I forgot to create the database itself!
I created the role and gave it the needed permissions, but forgot to create the database corresponding to my connection string.
The Postgres error code mentioned in my question (3D000) corresponds to invalid_catalog_name, i.e., no database corresponding to the connection string.
One may easily check this at Postgres documentation, but I was mistakenly looking for this error code at FeathersJS documentation.

Sails.js - Authorisation issues with remote MongoDB on mLab but working fine locally

Recently, I took over a Sails.js application created for our company by a small team of web developers. They provided me with the source and a database dump. Now, my task is to get it up and running on Heroku. While everything is working okay when I run the app locally, with the remote connection there is an error on startup that says:
MongoError: not authorized on heroku_gbntc8sf to execute command { createIndexes: "agendaJobs", indexes: [ { key: { name: 1, priority: -1, lockedAt: 1, nextRunAt: 1, disabled: 1 }, name: "findAndLockNextJobIndex1" }, { key: { name: 1, lockedAt: 1, priority: -1, nextRunAt: 1, disabled: 1 }, name: "findAndLockNextJobIndex2" } ] }
at Function.MongoError.create ([ROOT_DIR]/node_modules/mongodb-core/lib/error.js:31:11)
at [ROOT_DIR]/node_modules/mongodb-core/lib/topologies/server.js:793:66
at Callbacks.emit ([ROOT_DIR]/node_modules/mongodb-core/lib/topologies/server.js:94:3)
at null.messageHandler ([ROOT_DIR]/node_modules/mongodb-core/lib/topologies/server.js:235:23)
at Socket.<anonymous> ([ROOT_DIR]/node_modules/mongodb-core/lib/connection/connection.js:259:22)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:146:16)
at Socket.Readable.push (_stream_readable.js:110:10)
at TCP.onread (net.js:523:20)
Here's a quick checklist of what I've done already:
checked the build log on Heroku - no errors or warnings;
set up mLab Heroku add-on, exported the database, done some manual checks from the mLab dashboard - everything looks okay;
logged in to the database remotely from the mongo command and a mongo:// URL, ran a few simple queries, and obtained information on the database user privileges;
created an identical user (with the heroku_gbntc8sf username, same password, same role, etc.) in the local database.
Here's what the connection configuration looks like:
// config/connections.js
module.exports.connections = {
mongodb: {
adapter: 'sails-mongo',
user: 'heroku_gbntc8sf',
password: [HIDDEN],
host: 'ds159387.mlab.com',
port: 59387,
database: 'heroku_gbntc8sf'
},
// ...
}
// config/env/development.js
module.exports = {
models: {
connection: 'mongodb'
},
// ...
}
// config/env/production.js
module.exports = {
models: {
connection: 'mongodb'
},
// ...
}
At the moment I'm running the server locally, trying to connect to the remote database, to eliminate as many variables as possible. Like I mentioned above, when I set host to '127.0.0.1' and port to 27017, everything works okay. The heroku_gbntc8sf user has basic readWrite permissions in both databases (local and remote). In fact, those two databases are pretty much identical, as far as I know. And yet...
I've read a sizeable chunk of the Sails.js documentation, as well as, the documentation on the sails-mongo adapter. I've searched for similar questions, but I couldn't find anything relevant. I've tried many different things, including a couple of different ways to configure the database connection, but that error is always there.
The reason why I'm posting to StackOverflow is that I cannot rely on the support from the original authors of the app at the moment. Also, I'm new to Sails.js, so I might be doing something wrong without even knowing. I was hoping that I could get away with treating the app as a 'black box' (or like a generic Node application), since my job is only to start the app on Heroku.
I've successfully used mLab in a Sails project recently, but I've used the Mongo URL string format, for example...
mongodbServer: {
adapter: 'sails-mongo',
url : "mongodb://dandanknight:som3P455w0rd#ds044979.mlab.com:44979/databasename"
}
Not sure if it helps, but can't hurt to try! It's also the only way I've successfully got a replicaSet working in Sails incidentally.
It's confusing, but I read the sails-mongo docs as "URL is the way forward, and passing an object is legacy usage" (here)

Bluemix - error connecting loopback starter with mongoDB compose

I am trying to setup the loopback starter app on Bluemix with MongoDB. I have set up the MongoDB instance in Compose. However, when I keep getting a connection error even though I have followed all instructions and can even connect using the mongo shell.
{ [MongoError: connect ECONNREFUSED] name: 'MongoError', message: 'connect ECONNREFUSED' }
Take a look here: http://www.technicaladvices.com/2015/10/06/deploying-your-existing-strongloop-application-to-ibm-bluemix/
It shows the details of deploying a "StrongLoop" app in IBM Bluemix.
If the issue is still there open a support request directly from your Bluemix console or you can open a new ticket here: https://support.ng.bluemix.net/gethelp/
I was able to solve the problem by using the following configuration format in datasources.json:
"mongoDs": {
"host": "candidate.53.mongolayer.com",
"port": 10852,
"database": "SiteRite",
"username": "xxxx",
"password": "xxxx",
"name": "mongoDs",
"connector": "mongodb"
}
NOT using the 'url' key and using 'host' and 'port' with a separate 'username' and 'password' for the database is what seemed to have fixed it.