Sailsjs still uses the default database after changing it in mongodb

I am new to sailsjs and am currently working on a project that uses sailsjs. I want to change the default database to mongodb . I did this in config/local.js as shown below

 connections: { 'defaults': 'mongo', mongo: { module: 'sails-mongo', host: 'localhost', user: '', password: '', database: 'dbName', schema: true } } 

After starting mongodb and tried to create some data using the application (which I am working on), and then when I check that in mongodb using the mongodb command line tool . It does not find the data there, and when I check that in the application it loads all the data from the database. This means that it still uses the default database in which this data is stored.

I am using sailsjs version 0.11.0 .

+2
mongodb sails-mongo
source share
4 answers

There may be some problems with multiple named adapters.

It is best to name everything in a different way (also like MongoDev, MongoProd), and if your problem separates dev and production, but all your connection parameters and models by default in config / en / - production.js - development.js

You should check the following links

https://github.com/balderdashy/sails/issues/939

Processing database environment configuration in Sails.js

+2
source share

You need to change the connection used by your models in the models.js file located in the config folder. Installation:

 connection: 'mongo' 

In general, you can define your adapters in the connections.js file or in the local.js file. Local.js takes precedence and basically protects confidential configuration information (passwords, etc.), since it does not load with git. You still need to set which adapter to use in the models.js file.

+1
source share

Just run npm install sails-mongo

Put the configuration below on /config/connections.js

  mongodbServer: { adapter: 'sails-mongo', host: 'localhost', port: 27017, database: 'test', schema:true } 

Mention mongodbServer as shown below in /config/models.js

 connection: 'mongodbServer', migrate: 'alter' 
+1
source share

Is your adapter defined? In connection.js it will be

 localDiskDb: { adapter: 'sails-mongo' }, someMongodbServer: { adapter: 'sails-mongo', host: 'localhost', port: 27017, }, 

I'm new to swimming too, but I'm sure you don't need to touch local.js

0
source share

All Articles