**已关闭。**此问题需要debugging details。它目前不接受回答。
编辑问题以包括desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答这个问题。
9小时前关闭
Improve this question的
这是我在后端的index.js文件:(https://i.stack.imgur.com/HUq8T.png)
这是我的package.json文件:
(https://i.stack.imgur.com/6k168.png)
现在,在启动服务器时,这是弹出的错误:
PS C:\Users\Udit\Desktop\FinApp\server> npm run dev
> server@1.0.0 dev
> nodemon index.js
[nodemon] 3.0.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,cjs,json
[nodemon] starting `node index.js`
C:\Users\Udit\Desktop\FinApp\server\node_modules\muri\lib\index.js:28
throw new Error('Invalid mongodb uri "' + str + '". Must begin with "mongodb://"');
^
Error: Invalid mongodb uri "mongodb+srv://username:password@cluster0.yvdf17q.mongodb.net/?retryWrites=true&w=majority". Must begin with "mongodb://"
at muri (C:\Users\Udit\Desktop\FinApp\server\node_modules\muri\lib\index.js:28:11)
at Connection.openUri (C:\Users\Udit\Desktop\FinApp\server\node_modules\mongoose\lib\connection.js:766:18)
at Mongoose.connect (C:\Users\Udit\Desktop\FinApp\server\node_modules\mongoose\lib\index.js:262:17)
at file:///C:/Users/Udit/Desktop/FinApp/server/index.js:23:4
at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
Emitted 'error' event on NativeConnection instance at:
at Connection.error (C:\Users\Udit\Desktop\FinApp\server\node_modules\mongoose\lib\connection.js:673:8)
at Connection.openUri (C:\Users\Udit\Desktop\FinApp\server\node_modules\mongoose\lib\connection.js:77`your text`5:10)
at Mongoose.connect (C:\Users\Udit\Desktop\FinApp\server\node_modules\mongoose\lib\index.js:262:17)
at file:///C:/Users/Udit/Desktop/FinApp/server/index.js:23:4
at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
Node.js v18.17.0
[nodemon] app crashed - waiting for file changes before starting...
字符串
1条答案
按热度按时间p5fdfcr11#
你的 Mongoose 版本已经过时了。如果你想以你现在的方式连接,你需要升级它。尝试最新版本:
字符串
有documented issues使用
mongodb+srv
连接uri
方法与特定版本的MongoDB/Atlas/Node.js,特别是Mongoose V4.x。升级应该有帮助。