1

使用 "sails-mongo": "^0.10.0-rc2", "sails": "~0.10.0-rc4" 我在sails lift.

verbose: Loading adapter ( sails-mongo ) for algorithm  from `node_modules` directory...
Failed to load c++ bson extension, using pure JS version
verbose: Starting ORM...
error: A hook (`orm`) failed to load!
error: MongoError: auth fails
    at Object.toError (/home/default/Projects/machine_learning_data_sets/machine-learning-    engine/node_modules/sails-mongo/node_modules/mongodb/lib/mongodb/utils.js:110:11)
    at /home/default/Projects/machine_learning_data_sets/machine-learning-    engine/node_modules/sails-    mongo/node_modules/mongodb/lib/mongodb/auth/mongodb_cr.js:39:33
    at /home/default/Projects/machine_learning_data_sets/machine-learning-engine/node_modules/sails-mongo/node_modules/mongodb/lib/mongodb/db.js:1806:9
    at Server.Base._callHandler (/home/default/Projects/machine_learning_data_sets/machine-    learning-engine/node_modules/sails-    mongo/node_modules/mongodb/lib/mongodb/connection/base.js:442:41)
    at /home/default/Projects/machine_learning_data_sets/machine-learning-    engine/node_modules/sails-    mongo/node_modules/mongodb/lib/mongodb/connection/server.js:485:18
    at MongoReply.parseBody (/home/default/Projects/machine_learning_data_sets/machine-    learning-engine/node_modules/sails-    mongo/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js:68:5)
    at null.<anonymous> (/home/default/Projects/machine_learning_data_sets/machine-learning-    engine/node_modules/sails-        mongo/node_modules/mongodb/lib/mongodb/connection/server.js:443:20)
    at EventEmitter.emit (events.js:95:17)
    at null.<anonymous> (/home/default/Projects/machine_learning_data_sets/machine-learning-    engine/node_modules/sails-    mongo/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:191:13)
    at EventEmitter.emit (events.js:98:17)
verbose: Lowering sails...
verbose: Sent kill signal to child process (12033)...
verbose: Shutting down socket server...
verbose: Shutting down HTTP server...

这是在 mongo 控制台中可访问的本地 mongodb 上。

我的连接由

  mongo: {
    adapter   : 'sails-mongo',
    host      : 'localhost',
    port      : 27017,
    user      : '',
    password  : '',
    database  : 'mle'
  },
4

6 回答 6

1

在我的情况下,我使用 url 连接 mongodb,如下所示

adapter: 'sails-mongo',
url: 'mongodb://<USERNAME>:<PASSWORD>@<HOST>/<DATABASE>'
于 2019-04-13T13:50:49.220 回答
1

mongo:{适配器:'sails-mongo',主机:'localhost',端口:27017,用户:'',user: 'username', //optional 密码:'',password: 'password', //optional 数据库:'mle'},

用户名和密码是可选的,所以不需要提供,只需评论并运行它。它对我有用!

于 2016-08-18T10:59:18.423 回答
0

我遇到了同样的问题,我无法连接到导入的数据库,即使我尝试创建很多不同的用户,具有不同的角色。

所以我跑db.system.users.find()了,我注意到一个用户,我还没有创建它。是这样的:

{ "_id" : ObjectId("546699985feb7553f2e4dc32"), "user" : "newuser", "pwd" : "aaacf6ead2f12cbeb1a155b3021a3cda", "roles" : [ "userAdminAnyDatabase" ] }

所以我去了connections.js文件,在询问老程序员那个用户的密码是什么之后,更新了用户名和密码。

然后运行sails lift,幸运的是它成功了!

于 2015-03-29T21:33:23.013 回答
0

当我忘记更新到匹配的sails-mongo 包时,我遇到了各种sails 候选版本的问题。您可能会更新到最新版本,sails 0.10.5 和sails-mongo 0.10.4。这些一起工作。

于 2014-09-09T05:50:23.297 回答
0

您可能对未加载的 bson 扩展有问题。

你的第一个错误:

使用纯JS版本加载c++ bson扩展失败

多个来源可能:bson 或 node-gyp 已卸载或数据库不存在。

要解决依赖关系提供的错误(请在每次使用解决方案时检查,如果有人成功,请停止阅读我):

应用程序根目录中的第一个解决方案:

npm install

如果您在 OSX 上,第二个解决方案不起作用:

xcode-select --install
rm -rf node_modules // OR npm update
npm cache clean // OR npm update
npm install // OR npm update

在 Ubuntu 上,第二种解决方案:

sudo apt-get install gcc make build-essential
rm -rf node_modules // OR npm update
npm cache clean // OR npm update
npm install // OR npm update

如果您认为 bson 在依赖项下不存在,则第三个解决方案:

npm install bson

如果其他不起作用,也许这个可以拯救你:

npm install -g node-gyp 

如果它不起作用,则在它之后:

git clone https://github.com/mongodb/js-bson.git
cd js-bson
npm install
node-gyp rebuild

很抱歉这个 wtf 答案,但它可以帮助你或其他人。

此致

于 2015-04-21T16:00:25.657 回答
0

你可以像这样连接到数据库。

https://sailsjs.com/documentation/reference/configuration/sails-config-datastores

 // config/datastores.js
    module.exports.datastores = {
      default: {
        adapter: require('sails-mysql'),
        url: 'mysql://root:squ1ddy@localhost:3306/my_dev_db_name',
      }
    };
于 2020-07-29T09:27:26.253 回答