mongodb 如何在 Ubuntu 上运行 mongo shell

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36582692/
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:43:10  来源:igfitidea点击:

How to run the mongo shell on Ubuntu

mongodbubuntu

提问by L.D

I just installed MongoDB version 3.2.4 on Ubuntu 15.10 and I want to run the mongo shell. All docs are suggesting to execute first the command cd <mongodb installation dir>

我刚刚在 Ubuntu 15.10 上安装了 MongoDB 版本 3.2.4,我想运行 mongo shell。所有文档都建议先执行命令cd <mongodb installation dir>

My question is where is that mongodb installation dir? How I can find it?

我的问题是那是哪里mongodb installation dir?我怎样才能找到它?

Apparently it may be something wrong with the mongod. Could not find /usr/bin/mongodDetails below.

显然它可能有问题mongodCould not find /usr/bin/mongod详情如下。

root@levilinode:/usr/bin# service mongod status
● mongod.service - LSB: An object/document-oriented database
   Loaded: loaded (/etc/init.d/mongod)
   Active: active (exited) since Tue 2016-04-12 14:22:45 EDT; 1h 37min ago
     Docs: man:systemd-sysv-generator(8)

Apr 12 14:22:45 levilinode systemd[1]: Starting LSB: An object/document-oriented database...
Apr 12 14:22:45 levilinode mongod[16541]: Could not find /usr/bin/mongod
Apr 12 14:22:45 levilinode systemd[1]: Started LSB: An object/document-oriented database.
Apr 12 14:24:02 levilinode systemd[1]: Started LSB: An object/document-oriented database.
Apr 12 14:24:26 levilinode systemd[1]: Started LSB: An object/document-oriented database.
Apr 12 15:56:15 levilinode systemd[1]: Started LSB: An object/document-oriented database.

However that files seems to be there:

但是,该文件似乎在那里:

root@levilinode:/usr/bin# ls -la mong*
-rwxr-xr-x 1 root root 19816422 Mar  7 18:32 mongo
-rwxr-xr-x 1 root root 35865168 Mar  7 18:32 mongod
-rwxr-xr-x 1 root root 14661359 Mar  7 18:32 mongodump
-rwxr-xr-x 1 root root 10523458 Mar  7 18:32 mongoexport
-rwxr-xr-x 1 root root 10395740 Mar  7 18:32 mongofiles
-rwxr-xr-x 1 root root 10636848 Mar  7 18:32 mongoimport
-rwxr-xr-x 1 root root 10125973 Mar  7 18:32 mongooplog
-rwxr-xr-x 1 root root 35551461 Mar  7 18:32 mongoperf
-rwxr-xr-x 1 root root 17331345 Mar  7 18:32 mongorestore
-rwxr-xr-x 1 root root 16086077 Mar  7 18:32 mongos
-rwxr-xr-x 1 root root 10353518 Mar  7 18:32 mongostat
-rwxr-xr-x 1 root root 10213613 Mar  7 18:32 mongotop

采纳答案by L.D

I think I solved the connectivity problem based on this question:

我想我解决了基于这个问题的连接问题:

Then I run as indicated in the link shown above the commands:

然后我按照命令上方显示的链接中的指示运行:

sudo rm /var/lib/mongodb/mongod.lock
sudo service mongod restart

An now all seems to be working ok.

现在似乎一切正常。

回答by Anthony Perot

Multiple options:

多种选择:

  1. Using the system's files reference database:
  1. 使用系统的文件参考数据库:

$ sudo updatedb; locate mongo

$ sudo updatedb; locate mongo

  1. Restart your shell after install and try:
  1. 安装后重启你的 shell 并尝试:

Both mongo and mongod commands are in the same dir, so if this dir has been added in your $PATH by the installer, this should tell you where they are.

mongo 和 mongod 命令都在同一个目录中,所以如果这个目录已经被安装程序添加到你的 $PATH 中,这应该告诉你它们在哪里。

$ which mongo
$ which mongod
  1. check manually in /var/libor /usr/localor /usr/bin(must be a symlink though)
  2. check the daemon process line which usually give a hint about the path as it show the path of the config file
  1. 手动签入/var/lib/usr/local/usr/bin(但必须是符号链接)
  2. 检查守护进程行,它通常会提示有关路径,因为它显示了配置文件的路径

$ ps -efa | grep mongo

$ ps -efa | grep mongo

回答by TPWang

It would be in where you decompressed the tar.gz file that you downloaded from the MongoDB website. Inside, there is a mongod executable that you need to run before you can open the shell and operate the database.

它将在您解压缩从 MongoDB 网站下载的 tar.gz 文件的位置。在里面,有一个 mongod 可执行文件,您需要先运行它,然后才能打开 shell 并操作数据库。

Alternatively, you can create symlinks for the executables that you want to use:

或者,您可以为要使用的可执行文件创建符号链接:

sudo ln -s /dir/to/your/mongodb/folder/mongo /usr/local/bin/mongo
sudo ln -s /dir/to/your/mongodb/folder/mongod /usr/local/bin/mongod

And you can simply type in these two commands anywhere in terminal.

您可以在终端的任何位置简单地输入这两个命令。