gpt4 book ai didi

javascript - 使用 nodejs 连接到 mLab 数据库时出现错误并出现弃用警告

转载 作者:可可西里 更新时间:2023-11-01 10:38:48 24 4
gpt4 key购买 nike

我还是 node 的新手,目前使用的是 node 版本 10.5.0 和 mongoose 版本 5.1.7。我仔细检查了有关 mlab 的现有问题,但没有一个解决我的问题。我正在尝试连接到 mLab,这是我的代码:

const mongoose = require('mongoose');
const dbUri = 'mongodb://username:password@ds121371.mlab.com:21371/kucubookstore';

// connecting to mlab mongodb
mongoose.connect(dbUri, function(error) {
console.log('Connection Successful', error);
});

但是我收到以下错误,我不明白。请帮助:

E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue>node test/connection.js
Connection Successful Error: Missing delimiting slash between hosts and options
at parseConnectionString (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongodb\lib\url_parser.js:164:11)
at parseHandler (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongodb\lib\url_parser.js:129:14)
at module.exports (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongodb\lib\url_parser.js:25:12)
at connect (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongodb\lib\mongo_client.js:880:3)
at connectOp (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongodb\lib\mongo_client.js:270:3)
at executeOperation (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongodb\lib\utils.js:420:24)
at MongoClient.connect (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongodb\lib\mongo_client.js:261:10)
at Promise (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongoose\lib\connection.js:436:12)
at new Promise (<anonymous>)
at NativeConnection.Connection.openUri (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongoose\lib\connection.js:433:19)
at Mongoose.connect (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongoose\lib\index.js:212:15)
at Object.<anonymous> (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\test\connection.js:5:10)
at Module._compile (internal/modules/cjs/loader.js:702:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
(node:9016) UnhandledPromiseRejectionWarning: Error: Missing delimiting slash between hosts and options
at parseConnectionString (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongodb\lib\url_parser.js:164:11)
at parseHandler (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongodb\lib\url_parser.js:129:14)
at module.exports (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongodb\lib\url_parser.js:25:12)
at connect (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongodb\lib\mongo_client.js:880:3)
at connectOp (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongodb\lib\mongo_client.js:270:3)
at executeOperation (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongodb\lib\utils.js:420:24)
at MongoClient.connect (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongodb\lib\mongo_client.js:261:10)
at Promise (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongoose\lib\connection.js:436:12)
at new Promise (<anonymous>)
at NativeConnection.Connection.openUri (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongoose\lib\connection.js:433:19)
at Mongoose.connect (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\node_modules\mongoose\lib\index.js:212:15)
at Object.<anonymous> (E:\Documents\Computer and Coding\PlayGround\PROJECTS\Catalogue\test\connection.js:5:10)
at Module._compile (internal/modules/cjs/loader.js:702:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
(node:9016) 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(). (rejection id: 2)
(node:9016) [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.

最佳答案

当您的密码包含在 URL 中具有特殊含义的特殊字符(如 @)时,会发生此错误。尝试将密码更改为简单的内容,例如仅字母数字字符转义这些字符 ( https://www.w3schools.com/tags/ref_urlencode.asp)。

例如,如果您将密码设置为 one@two,则将其更改为 one%40two

如果您认为您的互联网提供商无法连接到该服务器,请尝试使用某些 VPN 进行连接。

关于javascript - 使用 nodejs 连接到 mLab 数据库时出现错误并出现弃用警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51090752/

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