[英]I've got into an error while connecting to mongodb and express and my terminal's gone mad
Here's the error.这是错误。 It's blowing me up.快把我炸了Please help.请帮忙。
It's just getting mad at me for something that is not supported.它只是因为一些不受支持的东西而生我的气。 And it's shouting at me not supported.它对我大喊大叫不支持。 I've never seen that many errors in the terminal.我从未在终端中看到过那么多错误。 Can anyone tell me why I am getting this.谁能告诉我为什么我得到这个。
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.
Server running on port 300
(node:6452) UnhandledPromiseRejectionWarning: MongooseError: Can't call `openUri()` on an active connection with different connection strings. Make sure you aren't calling `mongoose.connect()` multiple times. See: https://mongoosejs.com/docs/connections.html#multiple_connections at NativeConnection.Connection.openUri (C:\Users\hp\Documents\short shortnner-backend\node_modules\mongoose\lib\connection.js:682:13)
at C:\Users\hp\Documents\short shortnner-backend\node_modules\mongoose\lib\index.js:342:10
at C:\Users\hp\Documents\short shortnner-backend\node_modules\mongoose\lib\helpers\promiseOrCallback.js:31:5
at new Promise (<anonymous>)
at promiseOrCallback (C:\Users\hp\Documents\short shortnner-backend\node_modules\mongoose\lib\helpers\promiseOrCallback.js:30:10)
at Mongoose.connect (C:\Users\hp\Documents\short shortnner-backend\node_modules\mongoose\lib\index.js:341:10)
at Object.<anonymous> (C:\Users\hp\Documents\short shortnner-backend\models\Url.js:10:27) at Module._compile (internal/modules/cjs/loader.js:1138:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Module.require (internal/modules/cjs/loader.js:1026:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (C:\Users\hp\Documents\short shortnner-backend\routes\url.js:7:13)
at Module._compile (internal/modules/cjs/loader.js:1138:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
(node:6452) 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:6452) [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. 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.
Server running on port 300
(node:6452) UnhandledPromiseRejectionWarning: MongooseError: Can't call `openUri()` on an active connection with different connection strings. Make sure you aren't calling `mongoose.connect()` multiple times. See: https://mongoosejs.com/docs/connections.html#multiple_connections at NativeConnection.Connection.openUri (C:\Users\hp\Documents\short shortnner-backend\node_modules\mongoose\lib\connection.js:682:13)
at C:\Users\hp\Documents\short shortnner-backend\node_modules\mongoose\lib\index.js:342:10
at C:\Users\hp\Documents\short shortnner-backend\node_modules\mongoose\lib\helpers\promiseOrCallback.js:31:5
at new Promise (<anonymous>)
at promiseOrCallback (C:\Users\hp\Documents\short shortnner-backend\node_modules\mongoose\lib\helpers\promiseOrCallback.js:30:10)
at Mongoose.connect (C:\Users\hp\Documents\short shortnner-backend\node_modules\mongoose\lib\index.js:341:10)
at Object.<anonymous> (C:\Users\hp\Documents\short shortnner-backend\models\Url.js:10:27) at Module._compile (internal/modules/cjs/loader.js:1138:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Module.require (internal/modules/cjs/loader.js:1026:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (C:\Users\hp\Documents\short shortnner-backend\routes\url.js:7:13)
at Module._compile (internal/modules/cjs/loader.js:1138:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
(node:6452) 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:6452) [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.
MongoDB Connected...
It's all about mongo connection:这都是关于 mongo 连接的:
mongoose.connect
in ./models/url.js
are incorrect:你PARAMS传递给mongoose.connect
在./models/url.js
是不正确的: The first param of mongoose.connect
is a mongo connection string and the second is an options (passed down to mongo.connect) or a callback, which should be something like的第一个参数mongoose.connect
是蒙戈连接字符串,第二个是一个选项(向下传递到mongo.connect)或回调,这应该是这样的
module.exports = mongoose.connect('mongodb://user:pass@localhost:port/database', { useNewUrlParser: true });
You can find its offcial docs here: https://mongoosejs.com/docs/api/mongoose.html#mongoose_Mongoose-connect你可以在这里找到它的官方文档: https ://mongoosejs.com/docs/api/mongoose.html#mongoose_Mongoose-connect
mongoose.connect
is an async function, using require("../models/Url")
in ./routes/url.js
will lead to unexpected result.记住mongoose.connect
是一个异步函数,在./routes/url.js
使用require("../models/Url")
会导致意想不到的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.