caminte icon indicating copy to clipboard operation
caminte copied to clipboard

Unable to connect with mongoose

Open atha-github opened this issue 8 years ago • 1 comments

Please have a look, warning showing while connecting with mongoose:

(node:11516) DeprecationWarning: open() is deprecated in mongoose >= 4.11.0, use openUri() instead, or set the useMongoClient option if using connect() or createConnection(). See http://mongoosejs.com/docs/connections.html#use-mongo-client Server is running on http://localhost:8027 or http://127.0.0.1:8027 Db.prototype.authenticate method will no longer be available in the next major release 3.x as MongoDB 3.6 will only allow auth against users in the admin db and will no longer allow multiple credentials on a socket. Please authenticate using MongoClient.connect with auth credentials.

events.js:182 throw er; // Unhandled 'error' event ^ MongoError: Authentication failed. at Function.MongoError.create (E:\node\ormserver\node_modules\mongodb-core\lib\error.js:31:11) at E:\node\ormserver\node_modules\mongodb-core\lib\connection\pool.js:497:72 at authenticateStragglers (E:\node\ormserver\node_modules\mongodb-core\lib\connection\pool.js:443:16) at Connection.messageHandler (E:\node\ormserver\node_modules\mongodb-core\lib\connection\pool.js:477:5) at Socket. (E:\node\ormserver\node_modules\mongodb-core\lib\connection\connection.js:331:22) at emitOne (events.js:115:13) at Socket.emit (events.js:210:7) at addChunk (_stream_readable.js:252:12) at readableAddChunk (_stream_readable.js:239:11) at Socket.Readable.push (_stream_readable.js:197:10) at TCP.onread (net.js:588:20)

I also set mongoose.Promise = global.Promise; and schema.client = mongoose.connect(schema.settings.url, { useMongoClient: true }); in line number 36 After doing this I got following error:

(node:9904) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): MongoError: Authentication failed. (node:9904) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. (node:9904) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): MongoError: Authentication failed.

What should I do? How to connect with mongoose or mongodb? Any help... Thank You

atha-github avatar Nov 17 '17 13:11 atha-github

I just tried to connect to a Mongo DB right now and failed too. The first attempt was using the "mongodb" driver and it explodes on ".open" method (it seems is no more supported by mongodb)

After that I tried "mongoose" and everything went fine.

Here what I simply followed the documentation and added "mongoose" as a driver:

var caminte = require('caminte'),
    Schema = caminte.Schema,
    config = {
         driver     : "mongoose",
         host       : "localhost",
         port       : "3306",
         username   : "test",
         password   : "test",
         database   : "test",
         pool       : true // optional for use pool directly
    };

var schema = new Schema(config.driver, config);

Do you have the same problem by following the default behaviour described by the documentation ?

KingRial avatar Jan 31 '18 11:01 KingRial