sailsjs still uses default database after changing it to mongodb

牧云@^-^@ 提交于 2019-12-02 00:02:38
Meeker

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

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.

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'

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!