如何检查是否蒙戈DB是在Mac上运行? [英] How to check if mongo db is running on Mac?

查看:82
本文介绍了如何检查是否蒙戈DB是在Mac上运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了的MongoDB 几天回到我的Mac,我不知道我怎么安装,但现在我要如何检查是否的MongoDB 启动并在我的系统上运行?

I had installed MongoDB few days back on my Mac and am not sure how I installed, but now how do I check if MongoDB is up and running in my system?

推荐答案

运行以下命令:

ps -ef | grep mongod | grep -v grep | wc -l | tr -d ' '

这将让你的MongoDB 的数量进程中运行,因此如果它比 0 等,这时你系统上有的MongoDB 运行。

This will get you the number of MongoDB processes running, thus if it is other than 0, then you have MongoDB running on your system.


  • PS -ef | grep的mongod的 部分返回所有正在运行的进程,这有什么关系所提供的字符串,即的mongod ,例如在可执行文件路径字符串,在用户名等字符串。

  • The ps -ef | grep mongod part return all the running processes, that have any relation to the supplied string, i.e. mongod, e.g. have the string in the executable path, have the string in the username, etc.

当您运行previous命令时,的grep的mongod 也成为包含字符串的过程的mongod 命令 PS 输出列,因此它也将出现在输出中。出于这个原因,你需要通过管道来消除它的 的grep -v grep的 ,它过滤所有来自输入包含字符串的行的grep

When you run the previous command, the grep mongod also becomes a process containing the string mongod in the COMMAND column of ps output, so it will also appear in the output. For that reason you need to eliminate it by piping grep -v grep, which filters all the lines from the input that contain the string grep.

所以,现在你有一个包含字符串的所有可能的行的mongod ,不是的grep 的实例。该怎么办?算上他们,这样做是 WC -l <​​/ code>

So now you have all possible lines that contain string mongod and are not the instances of grep. What to do? Count them, and do that with wc -l.

WC -l <​​/ code>输出包含更多的格式,即空间,所以只为美容的缘故,运行 TR -d'' 以删除冗余空间。

wc -l output contains additional formatting, i.e. spaces, so just for the sake of the beauty, run tr -d ' ' to remove the redundant spaces.

因此​​,你会得到一个号码,再presenting的进程数您的grep 编辑的。

As a result you will get a single number, representing the number of processes you grep'ed for.

这篇关于如何检查是否蒙戈DB是在Mac上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆