gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 08:36:50 24 4
gpt4 key购买 nike

这是错误。快把我炸了请帮忙。
它只是因为一些不受支持的东西而生我的气。它对我大喊大叫不支持。我从未在终端中看到过那么多错误。谁能告诉我为什么我得到这个。

  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...
这是我的 code 的链接

最佳答案

这都是关于 mongo 连接的:

  • 您的参数传递给 mongoose.connect./models/url.js不正确:
  • mongoose.connect 的第一个参数是一个 mongo 连接字符串,第二个是一个选项(传递给 mongo.connect)或一个回调,应该是这样的
    module.exports = mongoose.connect('mongodb://user:pass@localhost:port/database', { useNewUrlParser: true });
    你可以在这里找到它的官方文档: https://mongoosejs.com/docs/api/mongoose.html#mongoose_Mongoose-connect
  • 请记住 mongoose.connect是一个异步函数,使用 require("../models/Url")./routes/url.js会导致意想不到的结果。
  • 关于node.js - 我在连接到 mongodb 和 express 时出错,我的终端发疯了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64762638/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com