Unable to connect with mongoose
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.
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
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 ?