MongoDB新手无法运行命令mongo

我正在尝试运行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 

我在看http://www.mongodb.org/display/DOCS/Quickstart+Windows并按照说明操作。 谁能告诉我什么是运行MongoDB的问题(我正在使用Windows 7)?

我认为你的日志输出清楚地说明了它;

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

您可以简单地创build这个目录,或者更好地将其定义为configuration文件中的configuration值,然后将其用作mongod -f C:\path\to\your\mongodb.conf

安装MongoDB后,你应该手动创build一个数据文件夹。

默认情况下,MongoDB将数据存储在/ data / db中, 
但不会自动创build该目录。 要创build它,请执行:

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

你也可以告诉MongoDB使用不同的数据目录,
用--dbpath选项。

有关更多详细信息,请访问MongoDB wiki页面。

像这样明确地指定数据库path,看看是否能解决问题。

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

运行上面的代码,这将启动服务器。

检查数据库数据文件的path是否存在;):

Sun 11月06日18:48:37 [initandlisten] initAndListen中的exception :10296 dbpath(/ data / db)不存在 ,终止

对于Windows 7

您可以使用mongod.exedbpath设置为 \data\db指定备用path,

如下例所示:

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

要么

您可以通过configuration文件设置dbpath

这适用于我(如果它适用,你也看到锁文件):

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

经过多次尝试,这对我的Windows 7环境工程:

最初复制到的目录所有的MongDB源都有这样的视图:

 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 

所有你需要的是添加数据目录和数据库目录嵌套(数据/数据库)最后的看法应该是这样的:

 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 

只需inputMongoDB源和数据/数据库目录存在的目录:

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

另外检查你是否已经安装了Mongo作为一个Windows服务,如果它的运行。 这也很重要。 有可能因此而造成冲突。

在主(Windows)分区中创builddata / db目录:

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

然后进入你的mongo_directory / bin并运行mongod.exe:

 C:\> cd \my_mongo_dir\bin C:\my_mongo_dir\bin> mongod 

不要closures这个窗口

现在在不同的命令提示符窗口中运行Mongo:

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

(记住,你必须保持其他窗口打开)

这解决了我的问题。

在工作目录中创build文件夹结构数据/ db,然后使用“mongod –dbpath data / db”启动mongodb,这样工作得很好

你应该创build一个startup.bat如果你使用Windows,更方便:

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

而dbclick startup.bat和mongodb将使用C:\mongodb\data作为其数据文件夹运行。

你只需要在C:中创build目录。 作为C:\ data \ db \

现在只需启动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) 

它将在后台运行。