xxxxxxxxxx
If you're using windows;
-Go to windows searchbar
-search for services and open it
-In services, search for MongoDB server
-right click on it and click on start
worked for me
xxxxxxxxxx
// instead of this
const url = "mongodb://localhost:27017";
// Just Replace
const url = "mongodb://127.0.0.1:27017";
// i wasted 5 hours while preparing for the exam because of this :'(
xxxxxxxxxx
// instead of this
const url = "mongodb://localhost:27017";
// Just Replace
const url = "mongodb://0.0.0.0:27017";
xxxxxxxxxx
If you are using latest nodejs -v > v17,
then try updating mongodb url from localhost to 127.0.0.1 This worked for me
const MONGODB_URL = "mongodb://127.0.0.1:27017";
/or
const MONGODB_URL = "mongodb://0.0.0.0:27017"
xxxxxxxxxx
//it's because you're using nodejs -v >17
//use this instead of "localhost"
let DBSTRING = "mongodb://127.0.0.1:27017"
//or
let DBSTRING = "mongodb://0.0.0.0:27017"
xxxxxxxxxx
//** How to start mongod in ubuntu, linux, debian **//
// check mongod status
=>sudo systemctl status mongod
// start mongod service
=>sudo systemctl start mongod
xxxxxxxxxx
// Try using 127.0.0.1 instead of localhost in connection url
// mongodb://localhost:27017
// mongodb://127.0.0.1:27017
const mongoose = require('mongoose');
mongoose.connect('mongodb://127.0.0.1:27017').then(() => {
console.log("connected to database");
})
xxxxxxxxxx
=>sudo systemctl start mongod
xxxxxxxxxx
npm config set proxy null
npm config set https-proxy null
npm config set registry http://registry.npmjs.org/