【问题标题】:How to properly add HOST using sails-mongo adapter?如何使用sails-mongo 适配器正确添加主机?
【发布时间】:2013-07-23 17:30:26
【问题描述】:

我已经通过 npm 安装了 sails-mongo 并运行了一个基本的 sails.js 应用程序 但它无法识别我的主机。

MongoDB 已启动并在默认端口 27017 上运行,但在生成模型后,尝试运行应用程序时出现此错误:

这是我的 adapter.js,我正在运行 node v0.10.0 和sails v0.8.895

// Configure installed adapters
// If you define an attribute in your model definition, 
// it will override anything from this global config.
module.exports.adapters = {

    // If you leave the adapter config unspecified 
    // in a model definition, 'default' will be used.
    'default': 'mongo',

    // In-memory adapter for DEVELOPMENT ONLY
    // (data is NOT preserved when the server shuts down)
    memory: {
        module: 'sails-dirty',
        inMemory: true
    },

    // Persistent adapter for DEVELOPMENT ONLY
    // (data IS preserved when the server shuts down)
    // PLEASE NOTE: disk adapter not compatible with node v0.10.0 currently 
    //              because of limitations in node-dirty
    //              See https://github.com/felixge/node-dirty/issues/34
    // disk: {
    //  module: 'sails-dirty',
    //  filePath: './.tmp/dirty.db',
    //  inMemory: false
    // },

     mongo: {
        module   : 'sails-mongo',
        url      : 'mongodb://Chris:DBPASSWORD@localhost:27017/localHostTestDB'
      }
};

我已经将用户添加到 localHostTestDB,角色为 admin。

任何帮助将不胜感激。谢谢!

【问题讨论】:

    标签: javascript mongodb sails.js


    【解决方案1】:

    最终不得不将sails.js 更新到0.9.3 版并使用sails-mongo 适配器:

    module.exports.adapters = {
    
      // If you leave the adapter config unspecified 
      // in a model definition, 'default' will be used.
      'default': 'mongo',
    
      mongo: {
        module   : 'sails-mongo',
        host     : 'localhost',
        user     : 'Chris',
        password : 'PASSWORD',
        database : 'localHostTestDB'
      },
    
      // In-memory adapter for DEVELOPMENT ONLY
      memory: {
        module: 'sails-memory'
      },
    
      // Persistent adapter for DEVELOPMENT ONLY
      // (data IS preserved when the server shuts down)
      disk: {
        module: 'sails-disk'
      },
    
      // // MySQL is the world's most popular relational database.
      // // Learn more: http://en.wikipedia.org/wiki/MySQL
      // mysql: {
      //   module: 'sails-mysql',
      //   host: 'YOUR_MYSQL_SERVER_HOSTNAME_OR_IP_ADDRESS',
      //   user: 'YOUR_MYSQL_USER',
      //   password: 'YOUR_MYSQL_PASSWORD',
      //   database: 'YOUR_MYSQL_DB'
      // }
    };
    

    【讨论】:

    • 您可能希望将 db 配置移动到 config/locals.js 文件。如果您使用 Git,则 gitignore 会忽略此文件,以避免您发布服务器配置。只需添加到module.exports obj:适配器:{'default':'mongo',mongo:{模块:'sails-mongo',主机:'localhost',用户:'Chris',密码:'PASSWORD',数据库: 'localHostTestDB' } }
    【解决方案2】:

    从 NPM 安装。 将 mongo 配置添加到 config/adapters.js 文件中。 访问http://sailsjs.org

    【讨论】:

    • 我的问题最终与sails 的版本有关,尽管github 上的一个问题说可以使用其他适配器对象。不过感谢您的帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-28
    • 2016-04-08
    • 2017-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多