Вот мой код подключения к базе данных
'use strict';
const config = require('../config');
const Mongoose = require('mongoose').connect(config.dbURI);
const mongoose = require('mongoose');
var options = {
promiseLibrary: require('bluebird'), useNewUrlParser: true, useUnifiedTopology: true
};
var mongodbUri = 'mongodb+srv://chatcat:chatcat@mychatcatdb-xlous.mongodb.net/test?retryWrites=true&w=majority'
mongoose.connect(mongodbUri, options);
var conn = mongoose.connection;
conn.on('error', console.error.bind(console, 'connection error:'));
module.exports = {
Mongoose
}
Я получаю предупреждение такого типа. Я также установил все необходимые пакеты. предупреждение просто как (узел: 17592) DeprecationWarning, (узел: 17592) UnhandledPromiseRejectionWarning. что является причиной этого типа предупреждения? я только начал учиться node js. пожалуйста, кто-нибудь, помогите мне решить это предупреждение?
D:\Node\ChatCAT\ChatCAT_Begin>node server
(node:17592) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
chatCat Running on Port: 3000
(node:17592) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
connection error: MongoNetworkError: failed to connect to server [mychatcatdb-shard-00-02-xlous.mongodb.net:27017] on first connect [MongoNetworkError: connection 5 to mychatcatdb-shard-00-02-xlous.mongodb.net:27017 closed
at TLSSocket.<anonymous> (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwonnection.js:372:9)
at Object.onceWrapper (events.js:418:26)
at TLSSocket.emit (events.js:311:20)
at net.js:668:12
at TCP.done (_tls_wrap.js:556:7) {
name: 'MongoNetworkError',
[Symbol(mongoErrorContextSymbol)]: {}
}]
at Pool.<anonymous> (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwerver.js:438:11)
at Pool.emit (events.js:311:20)
at D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwool.js:561:14
at D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwool.js:1008:9
at callback (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwonnect.js:97:5)
at D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwonnect.js:124:7
at _callback (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwonnect.js:349:5)
at Connection.errorHandler (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwonnect.js:365:5) at Object.onceWrapper (events.js:418:26)
at Connection.emit (events.js:311:20)
at TLSSocket.<anonymous> (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwonnection.js:370:12)
at Object.onceWrapper (events.js:418:26)
at TLSSocket.emit (events.js:311:20)
at net.js:668:12
at TCP.done (_tls_wrap.js:556:7) {
name: 'MongoNetworkError',
[Symbol(mongoErrorContextSymbol)]: {}
}
(node:17592) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [mychatcatdb-shard-00-02-xlous.mongodb.net:27017] on first connect [MongoNetworkError: connection 5 to mychatcatdb-shard-00-02-xlous.mongodb.net:27017 closed
at TLSSocket.<anonymous> (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwonnection.js:372:9)
at Object.onceWrapper (events.js:418:26)
at TLSSocket.emit (events.js:311:20)
at net.js:668:12
at TCP.done (_tls_wrap.js:556:7) {
name: 'MongoNetworkError',
[Symbol(mongoErrorContextSymbol)]: {}
}]
at Pool.<anonymous> (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwerver.js:438:11)
at Pool.emit (events.js:311:20)
at D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwool.js:561:14
at D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwool.js:1008:9
at callback (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwonnect.js:97:5)
at D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwonnect.js:124:7
at _callback (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwonnect.js:349:5)
at Connection.errorHandler (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwonnect.js:365:5) at Object.onceWrapper (events.js:418:26)
at Connection.emit (events.js:311:20)
at TLSSocket.<anonymous> (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwonnection.js:370:12)
at Object.onceWrapper (events.js:418:26)
at TLSSocket.emit (events.js:311:20)
at net.js:668:12
at TCP.done (_tls_wrap.js:556:7)
(node:17592) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:17592) [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.
connection error: MongooseError [MongooseServerSelectionError]: connection <monitor> to 3.7.80.251:27017 closed
at new MongooseServerSelectionError (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwction.js:22:11)
at NativeConnection.Connection.openUri (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGioose\lib\connection.js:823:32)
at Mongoose.connect (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGioose\lib\index.js:333:15)
at Object.<anonymous> (D:\Node\ChatCAT\ChatCAT_Begin\app\db\index.js:33:10)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGi.js:5:12)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (D:\Node\ChatCAT\ChatCAT_Begin\app\index.js:11:11)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14) {
message: 'connection <monitor> to 3.7.80.251:27017 closed',
name: 'MongooseServerSelectionError',
reason: TopologyDescription {
type: 'ReplicaSetNoPrimary',
setName: null,
maxSetVersion: null,
maxElectionId: null,
servers: Map {
'mychatcatdb-shard-00-00-xlous.mongodb.net:27017' => [ServerDescription],
'mychatcatdb-shard-00-01-xlous.mongodb.net:27017' => [ServerDescription],
'mychatcatdb-shard-00-02-xlous.mongodb.net:27017' => [ServerDescription]
},
stale: false,
compatible: true,
compatibilityError: null,
logicalSessionTimeoutMinutes: null,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
commonWireVersion: null
},
[Symbol(mongoErrorContextSymbol)]: {}
}
(node:17592) UnhandledPromiseRejectionWarning: MongooseServerSelectionError: connection <monitor> to 3.7.80.251:27017 closed
at new MongooseServerSelectionError (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwction.js:22:11)
at NativeConnection.Connection.openUri (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGioose\lib\connection.js:823:32)
at Mongoose.connect (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGioose\lib\index.js:333:15)
at Object.<anonymous> (D:\Node\ChatCAT\ChatCAT_Begin\app\db\index.js:33:10)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGi.js:5:12)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (D:\Node\ChatCAT\ChatCAT_Begin\app\index.js:11:11)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
(node:17592) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)