I've written a simple code to connect express js to mongodb, and I've installed both packages. However, I'm encountering an error. Can someone help me troubleshoot this?
const express = require("express");
const app = express();
app.listen(3000,() => {
console.log("Server is running at port number 3000");
})
const mongoose = require("mongoose");
mongoose.connect("mongodb://localhost:27017/myDatabase",{
useNewUrlParser:true,
useUnifiedTopology:true
})
.then(() => {console.log("Connection is Succeed")})
.catch((e) => { console.error("Received an Error", e); });
The error I'm facing is that they are not connecting properly.
Server is running at port number 3000
(node:25888) [MONGODB DRIVER] Warning: useNewUrlParser is a deprecated option: useNewUrlParser has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version
(Use `node --trace-warnings ...` to show where the warning was created)
(node:25888) [MONGODB DRIVER] Warning: useUnifiedTopology is a deprecated option: useUnifiedTopology has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version
Received an Error MongooseServerSelectionError: connect ECONNREFUSED ::1:27017
at _handleConnectionErrors (C:\Users\ASUS\OneDrive\Desktop\web dev\Backend Development\Express and MongoDB connections\node_modules\mongoose\lib\connection.js:809:11)
at NativeConnection.openUri (C:\Users\ASUS\OneDrive\Desktop\web dev\Backend Development\Express and MongoDB connections\node_modules\mongoose\lib\connection.js:784:11) {
reason: TopologyDescription {
type: 'Unknown',
servers: Map(1) { 'localhost:27017' => [ServerDescription] },
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: null,
maxElectionId: null,
maxSetVersion: null,
commonWireVersion: 0,
logicalSessionTimeoutMinutes: null
},
code: undefined
}