windows MongoDB 新手无法运行命令 mongo

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

New to MongoDB Can not run command mongo

windowsmongodb

提问by sophie

I was trying to run MongoDB:

我试图运行 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+Windowsand following the instructions. Could anyone tell me what is the problem with running MongoDB (I am using Windows 7)?

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

采纳答案by kirpit

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 itas a configuration value within your configuration file then use it as mongod -f C:\path\to\your\mongodb.conf.

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

回答by Fatih Acet

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

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

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.

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

回答by Socratees Samipillai

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

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

mongod --dbpath data/db

回答by dicemaster

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

run the above code, this will start the server.

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

回答by Zeeshan Akhter

For Windows 7

对于Windows 7

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

您可以使用mongod.exe\data\dbdbpath 设置指定备用路径,

as in the following example:

如下例所示:

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

or

或者

you can set dbpath through Configuration File.

您可以通过 Configuration File 设置 dbpath

回答by Andrew Orsich

Check that path to database data files exists ;) :

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

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

Sun Nov 06 18:48:37 [initandlisten] initAndListen 中的异常:10296 dbpath (/data/db) 不存在,正在终止

回答by dcparham

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*

回答by Artem Zaika

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

经过多次尝试,这在Windows 7 环境中对我有用。:

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

最初将所有 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

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

您只需要添加数据目录和db目录嵌套( data/db )最终视图应如下所示:

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:

比简单地输入 MongoDB 源和数据/数据库目录存在的目录,这个命令:

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

回答by laike9m

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

startup.bat如果您使用的是 Windows,您应该创建一个更方便的:

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\dataas its data folder.

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

回答by Raghav

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

在工作目录中创建文件夹结构 data/db,然后使用“mongod --dbpath data/db”启动 mongodb 工作正常