简体   繁体   English

我在连接到 mongodb 和 express 时出错,我的终端发疯了

[英]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...

Here's the link to my code这是我的代码的链接

It's all about mongo connection:这都是关于 mongo 连接的:

  1. Your params passed to 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

  1. Remember that 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.

相关问题 在 nodejs 中连接到 mongodb 时出现错误 - I got error while connecting to mongodb in nodejs 我在运行我的 Express 应用程序时遇到了这个错误 - I got this error while running my express app 当我尝试通过 express 更新 mongodb 中的字段值时,在控制台中收到一些错误信息 - got some error massage in console when I try to update my field value in mongodb through express 我已经安装了 nodejs,但尝试在终端中运行代码显示错误“找不到模块” - I've got nodejs installed but trying to run code in the terminal shows error "can't find module" 将 NodeJS 与 MongoDB 连接时出错 - Error while connecting NodeJS with MongoDB 在检查 mongodb 中的错误类型时我得到了未定义 - I got undefined while checking error kind in mongodb 我在验证 mongodb 中的字段时出错,nodejs - I got error while validating field in mongodb, nodejs 将数据库(MongoDB)与快速服务器连接时出错 - Error in connecting Database(MongoDB) with express server nodejs + express + mongodb:连接数据库时出错 - nodejs+express+mongodb: error connecting to database 当我将 firebase 与节点 js 连接时。 我得到了这个错误。 我如何修复此错误并将 firebase 连接到 node express 项目 - when I connecting firebase with node js. I got this error. how I fix this error and connect firebase to node express project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM