Node js Error: Mongoose with MondoDB connection string

蓝咒 提交于 2021-01-29 20:14:43

问题


after seting my connections

const mongoose = require('mongoose')

const Post = require('./database/models/Post')


mongoose.connect("mongodb://localhost/testdb", {useNewUrlParser: "true", useUnifiedTopology: true})

and my server page as below:

const mongoose = require('mongoose') const app = new express()

//mongoose.connect('mongodb://localhost/node-js-blog')
//mongoose.connect("mongodb://localhost:27017/node-js-blog", {useNewUrlParser: "true",})
mongoose.connect('mongodb://localhost/node-js-blog', {useNewUrlParser: "true", useUnifiedTopology: true})

i get this error while testing

enter image description here

(node:8744) UnhandledPromiseRejectionWarning: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017 at new MongooseServerSelectionError (C:\Users\Globalwise\Desktop\nodejs-blog\node_modules\mongoose\lib\error\serverSelection.js:22:11) at NativeConnection.Connection.openUri (C:\Users\Globalwise\Desktop\nodejs-blog\node_modules\mongoose\lib\connection.js:823:32) at Mongoose.connect (C:\Users\Globalwise\Desktop\nodejs-blog\node_modules\mongoose\lib\index.js:333:15) at Object. (C:\Users\Globalwise\Desktop\nodejs-blog\test.js:6:10) at Module._compile (internal/modules/cjs/loader.js:701:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10) at Module.load (internal/modules/cjs/loader.js:600:32) at tryModuleLoad (internal/modules/cjs/loader.js:539:12) at Function.Module._load (internal/modules/cjs/loader.js:531:3) at Function.Module.runMain (internal/modules/cjs/loader.js:754:12) at startup (internal/bootstrap/node.js:283:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3) (node:8744) 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: 1) (node:8744) [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.

please help as i have spent days debugging this.

Thanks all in advance.


回答1:


Is your MongoDB server running?



来源:https://stackoverflow.com/questions/61150387/node-js-error-mongoose-with-mondodb-connection-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!