0

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
  • have you imported express and all the other dependencies ? Please remove the error message and all the code from your main "server" file. Commented Apr 11, 2020 at 0:01

1 Answer 1

0

Is your MongoDB server running?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.