Error using geddy auth with MongoDB apapter - mongodb

first of all I'm a noob at Geddy so the answer might be something stupid I forgot, but I keep getting an error while using Geddy auth and MongoDB at the same time; Here's what I did:
geddy app myapp
Then I configured config/development.js to use MongoDB:
var config = {
detailedErrors: true
, debug: true
, hostname: null
, port: 4000
, model: {
defaultAdapter: 'mongo'
}
, db: {
mongo: {
dbname: 'myappdb'
}
}
, sessions: {
store: 'memory'
, key: 'sid'
, expiry: 14 * 24 * 60 * 60
}
};
module.exports = config;
Finally I installed geddy auth and launched the app:
geddy auth
geddy
When I navigate to localhost:4000/ everything seems to work fine at first, but if I refresh the page or try to create a new user, I get a beautiful Error: 500
Error: 500 Internal Server Error
Error: db object already connecting, open cannot be called multiple times
at Db.open (/usr/lib/node_modules/geddy/node_modules/model/node_modules/mongodb-wrapper/node_modules/mongodb/lib/mongodb/db.js:240:11)
at open (/usr/lib/node_modules/geddy/node_modules/model/node_modules/mongodb-wrapper/lib/mongodb-wrapper.js:625:20)
at self.connection (/usr/lib/node_modules/geddy/node_modules/model/node_modules/mongodb-wrapper/lib/mongodb-wrapper.js:618:9)
at connection (/usr/lib/node_modules/geddy/node_modules/model/node_modules/mongodb-wrapper/lib/mongodb-wrapper.js:190:18)
at /usr/lib/node_modules/geddy/node_modules/model/node_modules/mongodb-wrapper/lib/mongodb-wrapper.js:433:13
at cursor (/usr/lib/node_modules/geddy/node_modules/model/node_modules/mongodb-wrapper/lib/mongodb-wrapper.js:158:9)
at self.toArray (/usr/lib/node_modules/geddy/node_modules/model/node_modules/mongodb-wrapper/lib/mongodb-wrapper.js:135:16)
at utils.mixin.load (/usr/lib/node_modules/geddy/node_modules/model/lib/adapters/mongo/index.js:194:14)
at Object.obj.all (/usr/lib/node_modules/geddy/node_modules/model/lib/index.js:501:25)
at Function.obj.first (/usr/lib/node_modules/geddy/node_modules/model/lib/index.js:459:18)
I tried to update geddy using npm and to reinstall the mongo-adapter package but nothing's changed, I'm starting to get really frustrated as I can't find a solution and know it's probably just something simple I'm missing out.
Any idea of what is wrong ?
Thanks in advance for the help !

I think that you don't have MongoDB running...
To run your Geddy App you need both things, mongodb and geddy server running.
First of all, start your mongo server:
$ mongod
And later launch geddy on your root app directory
$ geddy
Hope that helps

Related

Postgres permissions.yml for fileLoad(permissions.yml) CONFIG_ERROR

I am following the https://deepstream.io/tutorials/plugins/database/postgres/
I have create a testDB with owner and permission to user james
In the conf/config.yml, I have the following configuration
plugins:
storage:
name: postgres
options:
user: james
database: testDB
password: james
host: localhost
port: 5432 #postgres default post
schema: ds #schema defaults to ds. Will be created if it doesn't exist
max: 10 #concurrent connections
idleTimeoutMillis: 30000 #timeout after which connection will be cut
writeInterval: 200 #amout of milliseconds during which writes will be buffered
notifications:
CREATE_TABLE: true #Get notified when tables are created
DESTROY_TABLE: true #Get notified when tables are dropped
INSERT: true # Get notified when records are created
UPDATE: false # Get notified when records are updated
However, when I run deepstream start, I got the following error
CONFIG_TRANSFORM | Loaded content from /Users/james/Workspace/deepstream.io/conf/permissions.yml for fileLoad(permissions.yml)
CONFIG_ERROR | Error loading module, exiting
Could someone please tell me what I have missed. Thank you for your help.
regards,
Johan
finally, I solved the problem, the configuration is correct, just to make sure that the postgres database and the role is done properly. The role needs to have a password and also LOGIN. Also, I clone the codes from github, so I can see what the error is when npm start. This will shows you verbose error message. If no error shown, npm test, this will show you all the missing packages and try to npm install again

Debugging connection PostgreSQL Loopback 4

Im on a mac(OS 10.14) using nodejs 14 and PostgresSQL 12.
I just installed Loopback4 and after following this tutorial Im not able to use any of the enpoints that use Models, ie that connect to Postgres, I constantly get a timeout.
It seems like its not even reaching the Postgres Server, but the error gives no information, just that the request times out.
There are no issues with the Postgres server since I can connect and request information with other nodejs applications to the same database.
I also tried to set this as the host host: '/var/run/postgresql/', same result.
I now tried the approach with a Docker container, setting the datasource files as follows:
import {inject, lifeCycleObserver, LifeCycleObserver} from '#loopback/core';
import {juggler} from '#loopback/repository';
const config = {
name: 'mydb',
connector: 'postgresql',
url: 'postgres://postgres:mysecretpassword#localhost:5434/test',
ssl: false,
};
// Observe application's life cycle to disconnect the datasource when
// application is stopped. This allows the application to be shut down
// gracefully. The `stop()` method is inherited from `juggler.DataSource`.
// Learn more at https://loopback.io/doc/en/lb4/Life-cycle.html
#lifeCycleObserver('datasource')
export class PostgresSqlDataSource extends juggler.DataSource
implements LifeCycleObserver {
static dataSourceName = 'PostgresSQL';
static readonly defaultConfig = config;
constructor(
#inject('datasources.config.PostgresSQL', {optional: true})
dsConfig: object = config,
) {
super(dsConfig);
}
}
With that same url I can log on my command line from my mac.
Is there a way to add logging and print any connection error? Other ways to debug it?
[UPDATE]
As of today Loopback4 Postgres connector does not work properly with Nodejs 14.
When starting the application, instead of running
npm start, you can set the debug string by running:
DEBUG=loopback:connector:postgresql npm start
If you want it to be more generic, you can use:
DEBUG=loopback:* npm start

MongoDB connecting to Node on AWS Mean stack

I have been trying for a few days to connect my mongoDB to MEAN stack without success. Its running on AWS lightsail (Bitnami). The website itself is running fine, except for any pages that have an ajax/db call, as the database is not connecting/authenticating my connection string.
I am using the mongo,node, express part of the stack, I do not need or know any angular at present. I thought this would be easier than setting up on nodeJS and then adding mongoDB separately (well i did try that first with similar problems), I do intend to learn angualar in future so this is probably better long term. Server side set up is currently a weakness.
I am using mongoose for the connection. I can access the database using:
mongo admin --username root -p password via SSH.
I can also access the db via Rockmongo SSH. There is currently only one admin user in the database at present i.e. root.
My initial server/startup file is below:
server.js
const app = require('/opt/bitnami/apps/MYAPP/app.js');
require('dotenv').config({ path: 'variables.env' });
const mongoose = require("mongoose");
mongoose.Promise = global.Promise;
mongoose.connect(process.env.DATABASE_CONN);
app.listen(3000,function(){
console.log("Server has started!");
});
variables.env
DATABASE_CONN = mongodb://root:password#127.0.0.1:27017/MYAPPDATABASE
I have also tried many other connections strings, exchanging root for bitnami default user, etc.
When I go to my app folder and start the server (npm start or node server.js), the website starts up but with the below mongoDB authentication errors, below is only the first section.
> Server has started!
Connection error: { MongoError: Authentication failed.
at /opt/bitnami/apps/MYAPP/node_modules/mongoose/node_modules/mongodb-core/lib/con
nection/pool.js:595:61
at authenticateStragglers (/opt/bitnami/apps/MYAPP/node_modules/mongoose/node_modu
les/mongodb-core/lib/connection/pool.js:513:16)
at Connection.messageHandler (/opt/bitnami/apps/MYAPP/node_modules/mongoose/node_m
odules/mongodb-core/lib/connection/pool.js:549:5)
at emitMessageHandler (/opt/bitnami/apps/MYAPP/node_modules/mongoose/node_modules/
mongodb-core/lib/connection/connection.js:309:10)
at Socket.<anonymous> (/opt/bitnami/apps/MYAPP/node_modules/mongoose/node_modules/
mongodb-core/lib/connection/connection.js:452:17)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
at Socket.Readable.push (_stream_readable.js:208:10)
at TCP.onread (net.js:597:20)
name: 'MongoError',
message: 'Authentication failed.',
ok: 0,
errmsg: 'Authentication failed.',
code: 18,
codeName: 'AuthenticationFailed' }
Any help or direction would be much appreciated. Thank you kindly.
Mos.
OK. Solution found.
In the mongo.conf file I set the dbpath to /data/db
The mongo shell is pointed to /opt/bitnami/mongodb/tmp/mongodb-27017.sock "$#"
go to /opt/bitnami/mongodb/bin/mongo
change /opt/bitnami/mongodb/tmp/mongodb-27017.sock "$#" to /tmp/mongodb-27017.sock "$#"
Can do that using sudo nano /opt/bitnami/mongodb/bin/mongo then edit the file.
Still have noauth turned on, so next step is getting my db connection string to authenticate.
Hope it helps someone.
Thanks
Some improvement. I have edited mongo.conf for now to enable no auth. I then ran mongod which stated no /data/db folder for which it stores data. So I created the folders and ran mongod again. Now all pages work but the mongo shell command 'mongo' will not work on the terminal.
I think its because the mongod dbpath is set to data/db and the mongodb conf file dbpath is set to /opt/bitnami/mongodb/data/db.
So I am trying to update the mongod dbpath but it doesnt seem to update.

SailsJS deployment to Heroku, connect to Mongolabs MongoDB

I am right now attempting my first Heroku deployment of a SailsJS API. My app uses SailsJS v0.11 andsails-mongo 0.11.2.
I have updated config/connections.js to include the connection information to MongoDB database I have hosted for free at Mongolab.
mongodb: {
adapter: 'sails-mongo',
url: "mongodb://db-user:password123#ds047812.mongolab.com:47812/testing-db"
}
Also updated config/models.js to point to that adapter.
module.exports.models = {
connection: 'mongodb',
migrate: 'safe'
};
This is basically all I have changed from running the code locally, when I deploy to Heroku the app crashes and I get this error...
/home/zacharyhustles/smallChangeAPI/node_modules/connect-mongo/lib/connect-mongo.js:186
throw err;
^
at Socket.emit (events.js:107:17)
2015-07-08T19:37:00.778316+00:00 app[web.1]:
at Socket.<anonymous> (/app/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/connection/connection.js:534:10)
Error: Error connecting to database: failed to connect to [localhost:27017]
How do I get rid of this, and make sure Sails does not try connecting to localhost db?
Ok, the problem was with storing sessions.
My solution was to setup a Redis database to store sessions.
In config/sessions.js make sure everything is commented out except for the method you want for session store.
Mine looked like this:
adapter: 'redis',
host: 'example.redistogo.com',
port: 1111,
db: '/redistogo',
pass: 'XXXXXYYYYYYXYXYXYYX',
This solved my posted problem, hope this helps another person out.

nodejs chat example does not work

I've come across a node chat example on github, When I try to run it, I see the following error:
Error connecting to mongo perhaps it isn't running ?
I've installed mongo 0.9.2, nodejs 5.2 pre, npm 3.0 and other dependencies. The example can be found here: https://github.com/gregstewart/chat.io
I can not determine whether if the example not really works or I didn't run it right. Please help.
Did you install and start mongo-db on your system? This error is mostly because of a missing mongo instance running on the local machine.
Check out the follwing code excerpts from chat.io.
main.js:
/**
* Configure the user provider (mongodB connection for user data storage)
*/
var userProvider = new UserProvider('localhost', 27017);
Creates a new UserProvider object using host and port for database (localhost:27017, mongo-db default).
UserProvider.js:
UserProvider = function(host, port) {
this.db = new mongo.Db('node-mongo-chat', new Server(host, port, {auto_reconnect: true}, {}));
this.db.addListener('error', function(error) {
console.log('Error connecting to mongo -- perhaps it isn\'t running?');
});
this.db.open(function() {
});
};
Opening the connection to the server, printing out an error on failure (the error you mentioned above).
Consider reading up on the mongo-db docs concerning installation and setup here