sailsjs still uses default database after changing it to mongodb
Asked Answered
K

4

2

I am new to sailsjs and currently working on project that uses sailsjs. I want to change the default database to mongodb. I did it in config/local.js like following

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 application(that I am working on), and then when I check that in mongodb using mongodb command line tool. It finds no data there and when I check that in application it loads all of the data from database. That means it is still using the default database where that data is stored.

I am using sailsjs version 0.11.0.

Kreindler answered 22/2, 2015 at 13:24 Comment(0)
P
2

There can be some issues with multiple named adapters.

It's best to completely name everything differently (aka MongoDev, MongoProd) and if your issue is separating dev and production, but all your connection and default model params in the config/env/ - production.js - development.js

You should check out the following links

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

Handling database environment configuration in Sails.js

Pinwheel answered 22/2, 2015 at 23:45 Comment(0)
S
1

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

connection: 'mongo'

In general, you can define your adapters in the connections.js file, or in your local.js file. Local.js takes precedence, and is mainly to protect sensitive configuration information (passwords, etc.) since it doesn't get uploaded with git. You still need to set which adapter to actually use in the models.js file.

Sherbet answered 24/2, 2015 at 2:5 Comment(0)
M
1

Just Run npm install sails-mongo

Put below configuration on /config/connections.js

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

Mention the mongodbServer as like below in /config/models.js

connection: 'mongodbServer',
migrate: 'alter'
Melba answered 13/7, 2015 at 16:13 Comment(0)
U
0

Is your adapter defined? In the connection.js it would be

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

I'm also new to sail but I'm pretty sure you don't need to touch to local.js

Ulla answered 22/2, 2015 at 15:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.