I'm making app with react and node.js and i install mongoose and espress and here is my connection:
mongoose.connect(process.env.MONGODB_URL || 'mongodb://localhost/shop', {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
});
i my steps for insalling mongodb are:
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
here status was OK, after that:
sudo apt-get update
sudo apt-get install -y mongodb-org
ps --no-headers -o comm 1
sudo systemctl start mongod
and then i got this error:
Failed to start mongod.service: Unit mongod.service not found.
tried to fix it like mongodb site suggested by deamon-reload and trying previous line again:
sudo systemctl daemon-reload
sudo systemctl start mongod
but again i got:
Failed to start mongod.service: Unit mongod.service not found
after that i tried checking status:
sudo systemctl status mongod
result of it is:
Unit mongod.service could not be found
and finally when i npm start backend i got this:
Serve at http://localhost:5000
(node:9530) UnhandledPromiseRejectionWarning: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
at NativeConnection.Connection.openUri (/home/sogla/shop/node_modules/mongoose/lib/connection.js:832:32)
at /home/sogla/shop/node_modules/mongoose/lib/index.js:345:10
at /home/sogla/shop/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:5
at new Promise (<anonymous>)
at promiseOrCallback (/home/sogla/shop/node_modules/mongoose/lib/helpers/promiseOrCallback.js:30:10)
at Mongoose._promiseOrCallback (/home/sogla/shop/node_modules/mongoose/lib/index.js:1135:10)
at Mongoose.connect (/home/sogla/shop/node_modules/mongoose/lib/index.js:344:20)
at file:///home/sogla/shop/backend/server.js:7:10
at ModuleJob.run (internal/modules/esm/module_job.js:152:23)
at async Loader.import (internal/modules/esm/loader.js:166:24)
at async Object.loadESM (internal/process/esm_loader.js:68:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:9530) 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(). To terminate the node process on
unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see
https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:9530) [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.
im stuck with this problem whole day i got tunnel vision so can someone help me out i really dont know where i making mistake