46

I am using MAC and I have successfully logged in to the server and started the server using the following command

./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:

./mongo

but its also a text there. Please help.

Developer
  • 6,375
  • 12
  • 58
  • 92

10 Answers10

62
mongo --shell

will open the shell interface.

https://docs.mongodb.com/manual/reference/program/mongo/

shakhawat
  • 2,639
  • 1
  • 20
  • 36
18

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.

Tad Marshall
  • 1,353
  • 8
  • 10
4

Just type mongod instead of ./mongod. It works for me.

Jia Li
  • 51
  • 3
3

bat command to start mongodb

create one folder for database like in this example 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
Praveen
  • 55,303
  • 33
  • 133
  • 164
Ravi Kumar
  • 1,903
  • 1
  • 11
  • 17
3

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

Or you can supply the full path to mongo.exe from any folder to start the shell:

c:\MongoDB\bin\mongo.exe

Then if you have multiple databases, you can do enter command >use <database_name> to use that db

Let me know if it helps or have issues

kheya
  • 7,546
  • 20
  • 77
  • 109
  • You need to leave the other shell window untouched. Otherwise, your mongodb server will not be running. You should write a simple batch file and put the start command on that batch file. Then just double click that file to start the server. – kheya Jul 14 '11 at 06:11
  • Thanks for reply but I am using Mac. You can identify by looking at the commands I used in my question. And ./mongo in Mac is similar to running mongo.exe on Windows. – Developer Jul 14 '11 at 06:11
  • mongod is for server daemon. You should be able to start the shell the same way as you did for the server. I am not familiar with mac and will never be. Can you find where the mongo? Then shell to that. Once done just type > show dbs to see the list of databases – kheya Jul 14 '11 at 06:24
3

Try this:

mongod --fork --logpath /var/log/mongodb.log

You may need to create the db-folder:

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.

cutsoy
  • 10,127
  • 4
  • 40
  • 57
0

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!

lejdale
  • 69
  • 6
0

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.

Seth Koch
  • 3
  • 1
0

In the terminal, use "mongo" command to switch the terminal into the 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.

Bugs
  • 4,491
  • 9
  • 32
  • 41
Malathy Venkatesan
  • 213
  • 1
  • 2
  • 8
0

just type mongosh in the shell.

Batman
  • 1