首页 > 解决方案 > 启动 mongod.service 失败:未找到单元 mongod.service。虽然我完成了所有步骤并且重新加载了守护进程

问题描述

我正在使用 react 和 node.js 制作应用程序,我安装了 mongoose 和 espress,这是我的连接:

mongoose.connect(process.env.MONGODB_URL || 'mongodb://localhost/shop', {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
});

我安装 mongodb 的步骤是:

wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -

这里的状态是好的,之后:

sudo apt-get update

sudo apt-get install -y mongodb-org

ps --no-headers -o comm 1

sudo systemctl start mongod

然后我得到了这个错误:

Failed to start mongod.service: Unit mongod.service not found.

尝试像 deamon-reload 建议的 mongodb 站点那样修复它并再次尝试上一行:

sudo systemctl daemon-reload
sudo systemctl start mongod

但我又得到了:

Failed to start mongod.service: Unit mongod.service not found

之后我尝试检查状态:

sudo systemctl status mongod

结果是:

Unit mongod.service could not be found

最后,当我 npm start 后端时,我得到了这个:

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.

我整天都被这个问题困扰着我有隧道视野所以有人可以帮助我我真的不知道我在哪里犯了错误

标签: javascriptnode.jsmongoose

解决方案


推荐阅读