UnhandledPromiseRejectionWarning: MongoParseError: Invalid connection string
at parseConnectionString (C:\Users\We'regonnalose\Desktop\newDB\node_modules\mongodb-core\lib\uri_parser.js:505:21)
at connect (C:\Users\We'regonnalose\Desktop\newDB\node_modules\mongoose\node_modules\mongodb\lib\operations\mongo_client_ops.js:195:3)
at connectOp (C:\Users\We'regonnalose\Desktop\newDB\node_modules\mongoose\node_modules\mongodb\lib\operations\mongo_client_ops.js:284:3)
at executeOperation (C:\Users\We'regonnalose\Desktop\newDB\node_modules\mongoose\node_modules\mongodb\lib\utils.js:416:24)
at MongoClient.connect (C:\Users\We'regonnalose\Desktop\newDB\node_modules\mongoose\node_modules\mongodb\lib\mongo_client.js:175:10)
at Promise (C:\Users\We'regonnalose\Desktop\newDB\node_modules\mongoose\lib\connection.js:612:12)
at new Promise (<anonymous>)
at NativeConnection.Connection.openUri (C:\Users\We'regonnalose\Desktop\newDB\node_modules\mongoose\lib\connection.js:609:19)
at Mongoose.connect (C:\Users\We'regonnalose\Desktop\newDB\node_modules\mongoose\lib\index.js:321:15)
at Object.<anonymous> (C:\Users\We'regonnalose\Desktop\newDB\app.js:3:10)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
(node:4716) 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: 3)
(node:4716) [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.
const mongoose=require('mongoose');
mongoose.connect('mongdb://localhost:27017/shopDB', {useNewUrlParser:true});
答案 0 :(得分:0)
您在连接字符串中有一个错字:
mongdb://localhost:27017/shopDB
它应该是mongodb
而不是mongdb
作为协议
mongodb://localhost:27017/shopDB