在Model中配置适配器

时间:2014-07-10 13:21:30

标签: sails.js

我使用帆0.9。 这是adapters.js代码:

module.exports.adapters = {

mongo: {
  module: 'sails-mongo',
  host: 'localhost',
  port: 27017,
  user: '',
  password: '',
  database: 'tracker'
},

mongo2: {
  module: 'sails-mongo',
  host: 'localhost',
  port: 27017,
  user: '',
  password: '',
}
};

模特:

module.exports = {

adapter: 'mongo2',

config: {
  database: 'offer'
},

attributes: {

  name: {
    type: 'string',
    unique: true,
    required: true
    }
}
};

从文档http://sailsjs.org/#!documentation/models我知道这个模型将保存在名为“offer”的数据库中,但它使用名为“sails”的数据库。看起来它只是忽略模型的配置部分。 我的错是什么?

1 个答案:

答案 0 :(得分:0)

您应该将数据库放在适配器配置中

mongo2: {
  module: 'sails-mongo',
  host: 'localhost',
  port: 27017,
  user: '',
  password: '',
  database: 'offer'
}