问题
Using "sails-mongo": "^0.10.0-rc2", "sails": "~0.10.0-rc4" I'm getting the following error on 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...
This is on a local mongodb that is reachable in the mongo console.
my connection is configured by
mongo: {
adapter : 'sails-mongo',
host : 'localhost',
port : 27017,
user : '',
password : '',
database : 'mle'
},
回答1:
I had trouble with various sails release candidates when I forgot to update to the matching sails-mongo package. You might update to the latest, sails 0.10.5 and sails-mongo 0.10.4. These work together.
回答2:
I had this same problem, I couldn't connect to an imported database, even though I tried by creating a lot of different users, with different roles.
So I run db.system.users.find(), and I notice a user, that I haven't created it. It was something like this:
{ "_id" : ObjectId("546699985feb7553f2e4dc32"), "user" : "newuser", "pwd" : "aaacf6ead2f12cbeb1a155b3021a3cda", "roles" : [ "userAdminAnyDatabase" ] }
So I went to the connections.js file, and after asking the old programmer what was the password for that user, and updated the username, and password.
Then just run sails lift, and luckily it had worked !
回答3:
You have probably troubles with your bson extension which is not loaded.
Your First Error:
Failed to load c++ bson extension, using pure JS version
Multiples origin possibles: bson or node-gyp unloaded or database is not present.
To solve an error providen by depedencies (please check each time you use a solution and stop reading me if any one succeed):
First Solution in the root directory of your application:
npm install
If it don't works second solution if you are on OSX:
xcode-select --install
rm -rf node_modules // OR npm update
npm cache clean // OR npm update
npm install // OR npm update
On Ubuntu the second solution:
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
Third solution if you think that bson is not présent under depedencies:
npm install bson
Maybe this one can save you if other doesn't work:
npm install -g node-gyp
After it if it doesn't work:
git clone https://github.com/mongodb/js-bson.git
cd js-bson
npm install
node-gyp rebuild
Sorry for this wtf answer but it could help you or someone else.
Best Regards
回答4:
mongo: {
adapter : 'sails-mongo',
host : 'localhost',
port : 27017,
user : '',user: 'username', //optional
password : '',password: 'password', //optional
database : 'mle'
},
user name and password are optional so don't need to give ,just comment it and run it .it's work for me!
回答5:
in my case i am using url for connect mongodb like below
adapter: 'sails-mongo',
url: 'mongodb://<USERNAME>:<PASSWORD>@<HOST>/<DATABASE>'
来源:https://stackoverflow.com/questions/22805608/sails-mongo-auth-error-in-sails-0-10