我来自riak和redis,在那里我从未有过这个服务启动或互动的问题。

这是蒙古人普遍存在的问题,我对此一无所知。重启也无济于事。我是蒙哥的新手。

mongo
MongoDB shell version: 2.2.1
connecting to: test
Fri Nov  9 16:44:06 Error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:91
exception: connect failed

这是我在日志里看到的。

 now open)
Fri Nov  9 16:44:34 [conn47] end connection 10.29.16.208:5306 (1 connection now open)
Fri Nov  9 16:45:04 [initandlisten] connection accepted from 10.29.16.208:5307 #48 (2 connections now open)
Fri Nov  9 16:45:04 [conn48] end connection 10.29.16.208:5307 (1 connection now open)
Fri Nov  9 16:45:04 [initandlisten] connection accepted from 10.29.16.208:5308 #49 (2 connections now open)
Fri Nov  9 16:45:04 [conn49] end connection 10.29.16.208:5308 (1 connection now open)
Fri Nov  9 16:45:34 [initandlisten] connection accepted from 10.29.16.208:5316 #50 (2 connections now open)
Fri Nov  9 16:45:34 [conn50] end connection 10.29.16.208:5316 (1 connection now open)
Fri Nov  9 16:45:34 [initandlisten] connection accepted from 10.29.16.208:5317 #51 (2 connections now open)
Fri Nov  9 16:45:34 [conn51] end connection 10.29.16.208:5317 (1 connection now open)
Fri Nov  9 16:46:04 [initandlisten] connection accepted from 10.29.16.208:5320 #52 (2 connections now open)
Fri Nov  9 16:46:04 [conn52] end connection 10.29.16.208:5320 (1 connection now open)
Fri Nov  9 16:46:04 [initandlisten] connection accepted from 10.29.16.208:5321 #53 (2 connections now open)
Fri Nov  9 16:46:04 [conn53] end connection 10.29.16.208:5321 (1 conn

当前回答

这是一个老问题了,但是,作为一个新手,我想我应该补充一点(使用Webstorm),你需要点击Mongo Explorer(窗口最右边的选项卡)。从这里开始:

单击设置。 -点击浏览按钮(看起来像一个带有“…”的按钮)。 -进入程序文件> MongoDB > Server > 3.4 > bin > mongo.exe(你的版本可能与3.4不同) -之后,点击右边的绿色加号。一扇窗将打开 -在“Label”插槽中输入名称。 单击apply。

您现在应该已连接。在终端输入“mongod”是不够的。您还必须执行上述步骤。

我提前向那些没有使用Webstorm的人道歉!不确定使用其他IDE的步骤。

其他回答

试试这个:

进入终端上的bin文件夹,然后写:

Sudo ./mongod——dbpath <write_here_the_path_to_your_database>,点击enter。(总是做同样的事情)。

然后在另一个终端窗口中写入:sudo ./mongo

mongodb(6.0.2及以上版本)的新版本将使用以下命令:sudo mongosh,或者如果连接到Atlas,它将是sudo mongosh "URI of mongodb +SERV"

记得下载并安装mongo shell,只需要复制bin文件夹中的文件并粘贴到mongod所在的根目录即可。

这是一个老问题了,但是,作为一个新手,我想我应该补充一点(使用Webstorm),你需要点击Mongo Explorer(窗口最右边的选项卡)。从这里开始:

单击设置。 -点击浏览按钮(看起来像一个带有“…”的按钮)。 -进入程序文件> MongoDB > Server > 3.4 > bin > mongo.exe(你的版本可能与3.4不同) -之后,点击右边的绿色加号。一扇窗将打开 -在“Label”插槽中输入名称。 单击apply。

您现在应该已连接。在终端输入“mongod”是不够的。您还必须执行上述步骤。

我提前向那些没有使用Webstorm的人道歉!不确定使用其他IDE的步骤。

Windows操作系统处理步骤:

删除mongod。锁定文件从C:\Program Files\MongoDB\Server\4.0\data 点击C:\Program Files\MongoDB\Server\4.0\bin上的mongod 点击C:\Program Files\MongoDB\Server\4.0\bin中的mongo启动mongodb shell

要连接mongo,我们必须首先启动“mongod”服务。 您可以看到以下输出:

$ mongod
2017-03-05T00:31:39.055+0530 I CONTROL  [initandlisten] MongoDB starting : pid=1481 port=27017 dbpath=/data/db 64-bit host=Prabhu-Nandans-Mac.local
2017-03-05T00:31:39.056+0530 I CONTROL  [initandlisten] db version v3.4.2
2017-03-05T00:31:39.056+0530 I CONTROL  [initandlisten] git version: 3f76e40c105fc223b3e5aac3e20dcd026b83b38b
2017-03-05T00:31:39.056+0530 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2k  26 Jan 2017
2017-03-05T00:31:39.056+0530 I CONTROL  [initandlisten] allocator: system
2017-03-05T00:31:39.056+0530 I CONTROL  [initandlisten] modules: none
2017-03-05T00:31:39.056+0530 I CONTROL  [initandlisten] build environment:
2017-03-05T00:31:39.056+0530 I CONTROL  [initandlisten]     distarch: x86_64
2017-03-05T00:31:39.056+0530 I CONTROL  [initandlisten]     target_arch: x86_64
2017-03-05T00:31:39.056+0530 I CONTROL  [initandlisten] options: {}
2017-03-05T00:31:39.056+0530 W -        [initandlisten] Detected unclean shutdown - /data/db/mongod.lock is not empty.
2017-03-05T00:31:39.057+0530 I -        [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2017-03-05T00:31:39.057+0530 W STORAGE  [initandlisten] Recovering data from the last clean checkpoint.
2017-03-05T00:31:39.057+0530 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=3584M,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2017-03-05T00:31:39.620+0530 I CONTROL  [initandlisten] 
2017-03-05T00:31:39.620+0530 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-03-05T00:31:39.620+0530 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-03-05T00:31:39.620+0530 I CONTROL  [initandlisten] 
2017-03-05T00:31:39.620+0530 I CONTROL  [initandlisten] 
2017-03-05T00:31:39.620+0530 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
2017-03-05T00:31:39.643+0530 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2017-03-05T00:31:39.643+0530 I NETWORK  [thread1] waiting for connections on port 27017
2017-03-05T00:31:40.008+0530 I FTDC     [ftdc] Unclean full-time diagnostic data capture shutdown detected, found interim file, some metrics may have been lost. OK
2017-03-05T00:32:03.832+0530 I NETWORK  [thread1] connection accepted from 127.0.0.1:49806 #1 (1 connection now open)
2017-03-05T00:32:03.833+0530 I NETWORK  [conn1] received client metadata from 127.0.0.1:49806 conn1: { application: { name: "MongoDB Shell" }, driver: { name: "MongoDB Internal Client", version: "3.4.2" }, os: { type: "Darwin", name: "Mac OS X", architecture: "x86_64", version: "16.4.0" } }
2017-03-05T00:32:08.376+0530 I -        [conn1] end connection 127.0.0.1:49806 (1 connection now open)

然后打开另一个终端,输入“mongo”。

输出如下:

$ mongo
MongoDB shell version v3.4.2
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.2

你的问题解决了:)

Resolved. This problem could be solved by the below mentioned 4 steps 1) Remove .lock file sudo rm /var/lib/mongodb/mongod.lock 2) repair the mongodb mongod -–repair 3) start the mongod server sudo service mongod start 4) start the mongo client mongo For more details take a look at http://shakthydoss.com/error-couldnt-connect-to-server-127-0-0-127017-srcmongoshellmongo-js-exception-connect-failed/ http://shakthydoss.com/technical/error-couldnt-connect-to-server-127-0-0-127017-srcmongoshellmongo-js-exception-connect-failed/