mongodb 如何启动mongodb shell?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6689017/
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
How to start mongodb shell?
提问by Developer
I am using MAC and I have successfully logged in to the server and started the server using the following command
我正在使用 MAC 并且我已成功登录到服务器并使用以下命令启动服务器
./mongod
then it says
然后它说
Thu Jul 14 01:50:41 db version v1.6.5, pdfile version 4.5
Thu Jul 14 01:50:41 git version: 0eb017e9b2828155a67c5612183337b89e12e291
Thu Jul 14 01:50:41 sys info: Linux domU-44-23-67-56-32-F5 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_37
Thu Jul 14 01:50:41 [initandlisten] waiting for connections on port 27017
Thu Jul 14 01:50:41 [websvr] web admin interface listening on port 28017
and after that whatever I write, its just a text. Terminal is not accepting any command. Response says "waiting for connections on port 27017". What should I do to get rid of this? I also tried command to start the Shell by the following commnad:
之后无论我写什么,它都只是一个文本。终端不接受任何命令。响应说“正在等待端口 27017 上的连接”。我该怎么做才能摆脱这种情况?我还尝试通过以下命令启动 Shell:
./mongo
but its also a text there. Please help.
但它也是那里的文字。请帮忙。
回答by shakhawat
mongo --shell
will open the shell interface.
将打开外壳界面。
回答by Tad Marshall
Both the mongod (database server) and mongo (database client shell) programs are command line programs and each expects to be run in its own command line session. So, after starting the server (as you did with "./mongod") you should open a second command line session and run "./mongo" in it to give you a command line shell for talking to the server.
mongod(数据库服务器)和 mongo(数据库客户端 shell)程序都是命令行程序,每个程序都希望在自己的命令行会话中运行。因此,在启动服务器之后(就像您使用“./mongod”所做的那样),您应该打开第二个命令行会话并在其中运行“./mongo”,以便为您提供一个用于与服务器对话的命令行外壳。
回答by Jia Li
Just type mongod
instead of ./mongod
. It works for me.
只需键入mongod
而不是./mongod
. 这个对我有用。
回答by Ravi Kumar
bat command to start mongodb
bat命令启动mongodb
create one folder for database like in this example r0
为数据库创建一个文件夹,如本例 r0
start /d "{path}\bin" mongod.exe --replSet foo --port 27017 --dbpath {path}mongoDataBase\r0
start /d "{path}\bin" mongo.exe 127.0.0.1:27017
回答by elslooo
Try this:
尝试这个:
mongod --fork --logpath /var/log/mongodb.log
You may need to create the db-folder:
您可能需要创建 db 文件夹:
mkdir -p /data/db
If you get any 'Permission denied'-error, I'ld recommend changing the permissions of the particular files instead of running mongod as root.
如果您收到任何“权限被拒绝”错误,我建议您更改特定文件的权限,而不是以 root 身份运行 mongod。
回答by kheya
You need to find the bin folder and then open a command prompt on that folder Then just type mongo.exe and press enter to start the shell
您需要找到 bin 文件夹,然后在该文件夹上打开命令提示符然后只需键入 mongo.exe 并按回车键启动 shell
Or you can supply the full path to mongo.exe from any folder to start the shell:
或者您可以从任何文件夹提供 mongo.exe 的完整路径以启动 shell:
c:\MongoDB\bin\mongo.exe
Then if you have multiple databases, you can do enter command >use <database_name>
to use that db
然后,如果您有多个数据库,则可以执行 enter 命令>use <database_name>
来使用该数据库
Let me know if it helps or have issues
让我知道它是否有帮助或有问题
回答by leon
You were in the correct folder if you got the ./mongod working! You now need to open another terminal, go to the same folder and type ./mongo the first terminal window serves as your server, the second is where you enter your commands!
如果你让 ./mongod 工作,你就在正确的文件夹中!您现在需要打开另一个终端,转到同一个文件夹并输入 ./mongo 第一个终端窗口作为您的服务器,第二个是您输入命令的地方!
回答by Seth Koch
Just right click on your terminal icon, and select open a new window. Now you'll have two terminal windows open. In the new window, type, mongo and hit enter. Boom, that'll work like it's supposed to.
只需右键单击您的终端图标,然后选择打开一个新窗口。现在您将打开两个终端窗口。在新窗口中,输入 mongo 并按回车键。Boom,它会像它应该的那样工作。
回答by Malathy Venkatesan
In the terminal, use "mongo" command to switch the terminal into the MongoDB shell:
在终端中,使用“mongo”命令将终端切换到 MongoDB shell:
$ mongo
MongoDB shell version: 2.6.10
connecting to: admin
>
Once you get >
symbol in the terminal, you have entered into the MongoDB shell.
>
在终端中获得符号后,您就进入了 MongoDB shell。