这是我的密码
const mongoose = require("mongoose");
mongoose.connect("mongodb:://localhost:27017/crudwithnode", {useNewUrlParser: true, useUnifiedTopology: true})
.then(() => console.log("MongoDB Connected..."))
.catch((err) => console.log(err));这就是我遇到的错误
Projects\Mongodb-with-nodeJs\node_modules\mongodb\lib\core\uri_parser.js:547:21):MongoParseError: parseConnectionString上的无效连接字符串(D:\Leraning Projects\Mongodb-with-nodeJs\node_modules\mongodb\lib\mongo_client.js:215:5 at connection ) (D:\Leraning Projects\Mongodb-with-nodeJs\node_modules\mongodb\lib\operations\connect.js:272:3) at D:\Leraning Projects\Mongodb-with-nodeJs\node_modules\mongodb\lib\mongo_client.js:215:5 at maybePromise ) (D:\Leraning \Mongodb-with-nodeJs\node_modules\mongodb\lib\utils.js:719:3) at Projects\Mongodb-with-nodeJs\node_modules\mongodb\lib\mongo_client.js:211:10) at MongoClient.connect (D:\Leraning Projects\Mongodb-with-nodeJs\node_modules\mongodb\lib\mongo_client.js:211:10) at D:\Leraning Projects\Mongodb-with-nodeJs\node_modules\mongoose\lib\connection.js:709:12 at new Promise () at NativeConnection.Connection.openUri ) (D:\Leraning \Mongodb-with-nodeJs\node_modules)Projects\Mongodb-with-nodeJs\node_modules\mongoose\lib\index.js:333:15) ( \mongoose\lib\connection.js:706:19) at Mongoose.connect (对象处为D:\Leraning)。(D:\Leraning \Mongodb\index.js:3:10)在Module._compile (内部/模块/cjs/loader.js:1158:30)的Object.Module._extensions..js (内部/模块/cjs/loader.js:1178:10)的Function.Module._load (内部/模块/cjs/loader.js:901:14)的Function.Module._load(内部/模块/cjs/loader.js:901:14)。内部/main/run_main_module.js:18:47{ name:'MongoParseError‘的executeUserEntryPoint as runMain,符号(MongoErrorContextSymbol):{} }
我只是试着用
节点"./index.js“
我能有个解决办法吗?
发布于 2020-04-15 07:46:07
您的URL字符串不是有效字符串。
有一个标准的URL结构,即
scheme://host:port/path?query-string#fragment-id
因此,要对某些资源提出任何有效请求,就必须遵循规则。相应地更新您的代码。
发布于 2020-04-15 07:36:27
由于错误消息已经声明,连接字符串无效。我怀疑这是因为连接字符串中的协议部分(mongodb)后面有两个冒号:mongodb:://localhost:27017/crudwithnode应该是mongodb://localhost:27017/crudwithnode。
发布于 2020-04-15 07:42:15
检查连接String.You在mongodb之后有两个“:”,而它必须只有一次。
mongoose.connect('mongodb://localhost/myapp');您可以在Mongodb连接字符串Spec找到更好的字符串结构细节。
https://stackoverflow.com/questions/61223574
复制相似问题