mongodb 如何检查 mongo db 是否在 Mac 上运行?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31561098/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 20:30:17  来源:igfitidea点击:

How to check if mongo db is running on Mac?

mongodbmacosinstallationosx-yosemite

提问by nshetty

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

我已经MongoDB在 Mac 上安装了几天,但不确定我是如何安装的,但是现在如何检查MongoDB我的系统是否已启动并正在运行?

回答by bagrat

Quick Solution

快速解决方案

Run the following in your Terminal:

在终端中运行以下命令:

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

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

这将为您提供MongoDB正在运行的进程数,因此如果它不是0,那么您已经MongoDB在您的系统上运行。

Step-by-Step

一步步

  • The ps -ef | grep mongodpart 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.

  • When you run the previous command, the grep mongodalso becomes a process containing the string mongodin the COMMANDcolumn of psoutput, 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.

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

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

  • ps -ef | grep mongod部分返回所有正在运行的进程,这些进程与提供的字符串有任何关系,即mongod,例如,在可执行路径中有字符串,在用户名中有字符串等。

  • 当您运行前面的命令时,grep mongod也变得包含字符串的过程mongodCOMMAND的列ps输出,所以它也将出现在输出。出于这个原因,您需要通过管道来消除它grep -v grep,这会过滤输入中包含字符串的所有行grep

  • 所以现在你有所有可能包含字符串的行,mongod而不是grep. 该怎么办?计算它们,然后使用wc -l.

  • wc -l输出包含额外的格式,即空格,所以为了美观,运行tr -d ' '删除多余的空格。

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

因此,您将获得一个数字,代表您所处理的进程数grep

回答by lastoneisbearfood

The answers combining psand grepshould always get you what you need. However, if you have a standard installation that comes with the mongo shell, an easier to remember method is to start the mongo shell

答案相结合psgrep应该总能满足您的需求。但是,如果您有 mongo shell 附带的标准安装,则更容易记住的方法是启动 mongo shell

mongo

The shell will give you status of mongodb.

shell 会给你 mongodb 的状态。

回答by Balepur

I had the same problem sometime ago. Using ps -ef(the process status command) will show if the mongodor the mongodb daemon is running. But if it is not running, it will yield a 0 as the status indicating mondodb is not there.

前一段时间我遇到了同样的问题。使用ps -ef(进程状态命令)将显示mongodmongodb 守护进程是否正在运行。但是如果它没有运行,它将产生一个 0 作为指示 mondodb 不在那里的状态。

However, if you want to check the installation via the system search on Mac, say using phrase such as mongod or mongodb, it will show the physical location of the installed directory and files starting with the searched phrase. If you get hold of this directory, you will see a bin directory, which will have binary files.

但是,如果您想通过 Mac 上的系统搜索来检查安装,例如使用 mongod 或 mongodb 等短语,它将显示已安装目录的物理位置和以搜索短语开头的文件。如果你得到这个目录,你会看到一个 bin 目录,里面有二进制文件。