I have started using CompoundJS with MongoDB as database.
I know i should do the host configuration in /config/database.json,
but not sure how i should add username/password for database configuration.
I tried to add username/password like below, but its not functional
{ "development":
{ "driver": "mongoose"
, "url": "mongodb://localhost/stats_development",
"username": "admin",
"password": "123456"
}
, "test":
{ "driver": "mongoose"
, "url": "mongodb://localhost/stats_test",
"username": "admin",
"password": "123456"
}
, "production":
{ "driver": "mongoose"
, "url": "mongodb://localhost/stats_production",
"username": "admin",
"password": "123456"
}
}
I found the solution..
mongodb://user:password#host:port/dbname
Thanks to Sagish, Reference : https://github.com/1602/compound/issues/377
Related
I exported NODE_ENV=local and defined my mongo datasource as follows in datasources.local.json
"mongo": {
"host": "localhost",
"port": 27017,
"url": "mongodb://localhost:27017/mydb",
"database": "mydb",
"password": "",
"name": "mongo",
"user": "",
"connector": "mongodb"
},
But the database name is getting created as 'test'.I also tried in datasources.json but it's still the same. I need the database name to be 'mydb'. Please help
What fixed the problem for me was to set the name of the object to "db" and not "mongo" or "mongods".
"db": {
"host": "localhost",
"port": 27017,
"url": "mongodb://localhost:27017/mydb",
"database": "mydb",
"password": "",
"name": "mongo",
"user": "",
"connector": "mongodb"
},
I just got started using strapi framework and I would like to use mLab as my mongoDB database, so I go to configure strapi and fill the following details:
{
"defaultConnection": "default",
"connections": {
"default": {
"connector": "strapi-mongoose",
"settings": {
"client": "mongo",
"host": "localhost",
"port": 27017,
"database": "development",
"username": "",
"password": ""
},
"options": {}
}
}
}
The details I get from mLab are:
mongodb://myUsername:myPassword#ds047891.mlab.com:41365/myDatabase
Here is my final config:
{
"defaultConnection": "default",
"connections": {
"default": {
"connector": "strapi-mongoose",
"settings": {
"client": "mongo",
"host": "ds047891.mlab.com",
"port": 41365,
"database": "myDatabase",
"username": "myUsername",
"password": "myPassword"
},
"options": {}
}
}
}
When I try to start strapi, I get the following error:
DEBUG (2748 on DESKTOP-HAL1ATE): Server wasn't able to start properly.
ERROR (2748 on DESKTOP-HAL1ATE): (hook:mongoose) takes too long to load
I think that I did not setup my configuration right, but I can't pinpoint where the problem is. I hope someone could, thanks.
I am Pierre, on of the creators of Strapi. I tried with the following configuration and it worked well:
{
"defaultConnection": "default",
"connections": {
"default": {
"connector": "strapi-mongoose",
"settings": {
"client": "mongo",
"host": "ds135777.mlab.com",
"port": "35777",
"database": "myDatabase",
"username": "myUsername",
"password": "myPassword"
},
"options": {}
}
}
}
Our configurations files look quiet similar.
What file did you updated (/config/environment/development/database.json or /config/environment/production/database.json)?
Are you sure you entered the correct username and password? Did you try to login to your MongoDB instance through the command line mongo ds135777.mlab.com:35777/myDatabase -u <dbuser> -p <dbpassword>?
UPDATE
In version >= 3 for mlab don't forget to specify authenticationDatabase
"options": {
"authenticationDatabase": "your_mlad_database_name",
"ssl": false
}
I try to do login to my application using local users kept in mongodb. My application works on Node.js using feathersjs. After run the app I receive an error like below:
Error: You must provide a 'header' in your authentication configuration or pass one explicitly
This is my config file:
{
"host": "localhost",
"port": 3030,
"public": "../public/",
"paginate": {
"default": 10,
"max": 50
},
"authentication": {
"secret": "My secret key",
"strategies": [
"jwt",
"local"
],
"path": "/authentication",
"service": "authentication",
"jwt": {
"header": {
"type": "access"
},
"audience": "https://yourdomain.com",
"subject": "anonymous",
"issuer": "feathers",
"algorithm": "HS256",
"expiresIn": "1d"
},
"local": {
"entity": "user",
"usernameField": "email",
"passwordField": "password"
}
},
"mongodb": "mongodb://localhost:27017/mydb"
}
What is wrong with this?
This was a bug in a recent version of feathers-cli which has been fixed in v2.3.7 so make sure feathers --version show that version. In an existing application you can fix the error message with by changing src/app.js from
app.configure(jwt(config.jwt));
app.configure(local(config.local));
To
app.configure(jwt());
app.configure(local());
I tried to follow this example
https://docs.strongloop.com/display/public/LB/Connector+hooks
var connector = MyModel.getDataSource().connector;
connector.observe('before execute', function(ctx, next) {
// ...
next();
});
But the property 'connector' seems to be undefined. I need to add a connector hook in the boot script. Any idea?
Use something like this to add a connector.
In server/datasource.json
{
"db": {
"host": "",
"port": 0,
"database": "",
"password": "",
"name": "db",
"connector": "memory",
"user": ""
},
"mongodb": {
"host": "0.0.0.0",
"port": 27017,
"database": "drugcorner",
"password": "12345",
"name": "mongodb",
"connector": "mongodb",
"user": "robins"
}
}
We have have MongoDb datasource datasource defined with name mongodb.
Now to use a connector for mongodb inside any boot files.
server/boot/testConnector.js
var mongoConnector = app.dataSources.mongodb.connector;
I am trying to install and run this node.js chat: https://github.com/dual3nigma/Mejorando.la-Chat.
When I type "npm install" and "node server" it starts, but with an Express error. I think the reason is in the config.json file.
This is my config.json file. I've only changed the db name and port of the config.sample.json file and added my twitter / facebook keys:
{
"port": 721,
"host": "localhost",
"db": {
"name": "V1chatCCI"
},
"twitter": {
"consumerKey": "XXXXXXXXXXXXXXXXXXXXXXXXXX",
"consumerSecret": "XXXXXXXXXXXXXXXXXXXXXXXXXXXX"
},
"facebook": {
"appId": "XXXXXXXXXXXXXXXXXXXXXXXX",
"appSecret": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
},
"session": {
"secret": "",
"key": ""
},
"cookie": {
"secret": ""
},
"secure": false,
"loginsecure": false,
"key": "",
"cert": "",
"sentry": "dsn"
}
What do I need to put in the session secret/key section? The error on localhost:721 is:
Express
500 Error: secret option required for sessions
You should be able to put anything in those sections, as they're used used internally by express handling sessions. Any values (even just random strings) should fix your problem.