New to MongoDB Can not run command mongo

WindowsMongodb

Windows Problem Overview


I was trying to run MongoDB:

   E:\mongo\bin>mongod
    mongod --help for help and startup options
    Sun Nov 06 18:48:37
    Sun Nov 06 18:48:37 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
    Sun Nov 06 18:48:37
    Sun Nov 06 18:48:37 [initandlisten] MongoDB starting : pid=7108 port=27017 dbpath=/data/db 32-bit host=pykhmer-PC
    Sun Nov 06 18:48:37 [initandlisten]
    Sun Nov 06 18:48:37 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
    Sun Nov 06 18:48:37 [initandlisten] **       see http://blog.mongodb.org/post/137788967/32-bit-limitations
    Sun Nov 06 18:48:37 [initandlisten] **       with --journal, the limit is lower
    Sun Nov 06 18:48:37 [initandlisten]
    Sun Nov 06 18:48:37 [initandlisten] db version v2.0.1, pdfile version 4.5
    Sun Nov 06 18:48:37 [initandlisten] git version: 3a5cf0e2134a830d38d2d1aae7e88cac31bdd684
    Sun Nov 06 18:48:37 [initandlisten] build info: windows (5, 1, 2600, 2, 'Service Pack 3') BOOST_LIB_VERSION=1_42
    Sun Nov 06 18:48:37 [initandlisten] options: {}
    Sun Nov 06 18:48:37 [initandlisten] exception in initAndListen: 10296 dbpath (/data/db) does not exist, terminating
    Sun Nov 06 18:48:37 dbexit:
    Sun Nov 06 18:48:37 [initandlisten] shutdown: going to close listening sockets...
    Sun Nov 06 18:48:37 [initandlisten] shutdown: going to flush diaglog...
    Sun Nov 06 18:48:37 [initandlisten] shutdown: going to close sockets...
    Sun Nov 06 18:48:37 [initandlisten] shutdown: waiting for fs preallocator...
    Sun Nov 06 18:48:37 [initandlisten] shutdown: closing all files...
    Sun Nov 06 18:48:37 [initandlisten] closeAllFiles() finished
    Sun Nov 06 18:48:37 dbexit: really exiting now

E:\mongo\bin>mongo
MongoDB shell version: 2.0.1
connecting to: test
Sun Nov 06 18:48:42 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
exception: connect failed

E:\mongo>ls
GNU-AGPL-3.0  README  THIRD-PARTY-NOTICES  bin  data

I was looking at http://www.mongodb.org/display/DOCS/Quickstart+Windows and following the instructions. Could anyone tell me what is the problem with running MongoDB (I am using Windows 7)?

Windows Solutions


Solution 1 - Windows

After installing the MongoDB you should manually create a data folder.

By default MongoDB will store data in /data/db,
but it won't automatically create that directory. To create it, do:

$ sudo mkdir -p /data/db/ $ sudo chown id -u /data/db

You can also tell MongoDB to use a different data directory, with the --dbpath option.

For more detailed information go to MongoDB wiki page.

Solution 2 - Windows

I think your log output states it clearly;

exception in initAndListen: 10296 dbpath (/data/db) does not exist, terminating

You may simply create this directory or better to define it as a configuration value within your configuration file then use it as mongod -f C:\path\to\your\mongodb.conf.

Solution 3 - Windows

Specify the database path explicitly like so, and see if that resolves the issue.

mongod --dbpath data/db

Solution 4 - Windows

mongod --dbpath "c://data/db"

run the above code, this will start the server.

Solution 5 - Windows

For Windows 7

You may specify an alternate path for \data\db with the dbpath setting for mongod.exe,

as in the following example:

c:\mongodb\bin\mongod.exe --dbpath c:\mongodb\data\db

or

you can set dbpath through Configuration File.

Solution 6 - Windows

Check that path to database data files exists ;) :

> Sun Nov 06 18:48:37 [initandlisten] exception in initAndListen: 10296 > dbpath (/data/db) does not exist, terminating

Solution 7 - Windows

This worked for me (if it applies that you also see the lock file):

first>youridhere@ubuntu:/var/lib/mongodb$ sudo service mongodb start 
then >youridhere@ubuntu:/var/lib/mongodb$ sudo rm mongod.lock*

Solution 8 - Windows

After several attempts this works for me on Windows 7 env.:

Initially directory to which you have copied all MongDB sources has such view:

bsondump.exe
mongo.exe
mongod.exe
mongod.pdb
mongodump.exe
mongoexport.exe
mongofiles.exe
mongoimport.exe
mongooplog.exe
mongoperf.exe
mongorestore.exe
mongos.exe
mongos.pdb
mongostat.exe
mongotop.exe

All you need is to add data directory and db directory nested( data/db ) Final view should look like this:

data
bsondump.exe
mongo.exe
mongod.exe
mongod.pdb
mongodump.exe
mongoexport.exe
mongofiles.exe
mongoimport.exe
mongooplog.exe
mongoperf.exe
mongorestore.exe
mongos.exe
mongos.pdb
mongostat.exe
mongotop.exe

Than simply type in directory where MongoDB sources and data/db dirs exist this command:

C:\my_mongo_dir\bin>mongod --dbpath .\data\db

Solution 9 - Windows

Create the data/db directory in your main (windows) partition:

C:\> mkdir \data
C:\> mkdir \data\db

and then go to your mongo_directory/bin and run mongod.exe:

C:\> cd \my_mongo_dir\bin

C:\my_mongo_dir\bin> mongod

DON't CLOSE THIS WINDOW

Now in a different command prompt window run Mongo:

C:\> cd \my_mongo_dir\bin
C:\my_mongo_dir\bin> mongo

(REMEMBER YOU HAVE TO KEEP THAT OTHER WINDOW OPEN)

This solved the problem for me.

Solution 10 - Windows

Also check if you have installed the Mongo as a windows service and if its running. That's also important. There might port conflict because of that.

Solution 11 - Windows

create folder structure data/db in the working directory and then starting up mongodb using "mongod --dbpath data/db" works just fine

Solution 12 - Windows

You should create a startup.bat if you're using Windows, much more convenient:

C:\mongodb\mongodb-win32-x86_64-eiditon\bin\mongod.exe --dbpath C:\mongodb\data

And just dbclick startup.bat and mongodb will run using C:\mongodb\data as its data folder.

Solution 13 - Windows

You just need to create directory in C:. as C:\data\db\

Now just start mongoDB:

C:\Users\gi.gupta>"c:\Program Files\MongoDB\Server\3.2\bin\mongod.exe"
2016-05-03T10:49:30.412+0530 I CONTROL  [main] Hotfix KB2731284 or later update is not installed, will zero-out data files
2016-05-03T10:49:30.414+0530 I CONTROL  [initandlisten] MongoDB starting : pid=7904 port=27017 dbpath=C:\data\db\ 64-bit host=GLTPM-W036
2016-05-03T10:49:30.414+0530 I CONTROL  [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2016-05-03T10:49:30.414+0530 I CONTROL  [initandlisten] db version v3.2.6
2016-05-03T10:49:30.414+0530 I CONTROL  [initandlisten] git version: 05552b562c7a0b3143a729aaa0838e558dc49b25
2016-05-03T10:49:30.414+0530 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1p-fips 9 Jul 2015
2016-05-03T10:49:30.414+0530 I CONTROL  [initandlisten] allocator: tcmalloc
2016-05-03T10:49:30.414+0530 I CONTROL  [initandlisten] modules: none
2016-05-03T10:49:30.414+0530 I CONTROL  [initandlisten] build environment:
2016-05-03T10:49:30.414+0530 I CONTROL  [initandlisten]     distmod: 2008plus-ssl
2016-05-03T10:49:30.414+0530 I CONTROL  [initandlisten]     distarch: x86_64
2016-05-03T10:49:30.414+0530 I CONTROL  [initandlisten]     target_arch: x86_64
2016-05-03T10:49:30.414+0530 I CONTROL  [initandlisten] options: {}
2016-05-03T10:49:30.427+0530 I -        [initandlisten] Detected data files in C:\data\db\ created by the 'wiredTiger' storage engine, so setting the active storage engine to
2016-05-03T10:49:30.429+0530 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=1G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(f
chive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2016-05-03T10:49:30.998+0530 I NETWORK  [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
2016-05-03T10:49:30.998+0530 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory 'C:/data/db/diagnostic.data'
2016-05-03T10:49:31.000+0530 I NETWORK  [initandlisten] waiting for connections on port 27017
2016-05-03T10:49:40.766+0530 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:57504 #1 (1 connection now open)

It will then run as service in background.

Solution 14 - Windows

If you're using Windows 7/ 7+.

Here is something you can try. >Check if the installation is proper in CONTROL PANEL of your computer.

Now goto the directory and where you've install the MongoDB. Ideally, it would be in

>C:\Program Files\MongoDB\Server\3.6\bin

Then either in the command prompt or in the IDE's terminal. Navigate to the above path ( Ideally your save file) and type

>mongod --dbpath

It should work alright!

Solution 15 - Windows

The very simplest approach given by mongo README help file

RUNNING

For command line options invoke:

$ ./mongod --help

To run a single server database:

$ sudo mkdir -p /data/db
$ ./mongod
$
$ # The mongo javascript shell connects to localhost and test database by default:
$ ./mongo
> help

If you are working with windows, go to your directory where you have mongo.exe

use the following commands, (I am sharing mine)

C:\Program Files\MongoDB\Server\3.6\bin>mkdir \data

C:\Program Files\MongoDB\Server\3.6\bin>mkdir \data\db

C:\Program Files\MongoDB\Server\3.6\bin>mongod ## this will start your mongoDB server

Now you need to run another CMD prompt and go to the directory where you have mongo and just run it

C:\Program Files\MongoDB\Server\3.6\bin>mongo ## this will start your mongoDB client

Hope it helped :)

If it doesn't work, run CMD as an administrator

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsophieView Question on Stackoverflow
Solution 1 - WindowsFatih AcetView Answer on Stackoverflow
Solution 2 - WindowskirpitView Answer on Stackoverflow
Solution 3 - WindowsSocratees SamipillaiView Answer on Stackoverflow
Solution 4 - WindowsdicemasterView Answer on Stackoverflow
Solution 5 - WindowsZeeshan AkhterView Answer on Stackoverflow
Solution 6 - WindowsAndrew OrsichView Answer on Stackoverflow
Solution 7 - WindowsdcparhamView Answer on Stackoverflow
Solution 8 - WindowsArtem ZaikaView Answer on Stackoverflow
Solution 9 - WindowsShobhit SharmaView Answer on Stackoverflow
Solution 10 - WindowsSiva KarthikeyanView Answer on Stackoverflow
Solution 11 - WindowsRaghavView Answer on Stackoverflow
Solution 12 - Windowslaike9mView Answer on Stackoverflow
Solution 13 - WindowsGirish GuptaView Answer on Stackoverflow
Solution 14 - WindowsRakesh DeshpandeView Answer on Stackoverflow
Solution 15 - WindowsAsh UpadhyayView Answer on Stackoverflow