无法连接mongodb errno:61连接拒绝。

时间:2022-09-18 23:06:42

I recently installed mongodb-2.6.0 with Homebrew. After successfully installed, I tried to connect using the mongo command. I am receiving the following errors which do not allow me to connect:

我最近安装了Homebrew的mongodb-2.6.0。成功安装之后,我尝试使用mongo命令连接。我收到以下错误,不允许我联系:

Failed to connect to 127.0.0.1:27017, reason: errno:61 Connection refused

Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146

exception: connect failed

11 个解决方案

#1


254  

It can happen when the mongodb service is not running on the mac. To start it, I tried

当mongodb服务没有在mac上运行时,就会发生这种情况。

brew services start mongodb

and it worked.

它工作。

Edit: According to the discussion on this PR on homebrew: https://github.com/Homebrew/homebrew/issues/30628

编辑:根据在homebrew上的讨论:https://github.com/homebrew/homebrew/es/30628。

brew services is deprecated, I looked around on SO and found these answers now answer the question: What is the correct way to start a mongod service on linux / OS X?

brew服务被弃用,我查看了一下,发现这些答案现在回答了一个问题:在linux / OS X上启动mongod服务的正确方法是什么?

#2


26  

I encountered the exact same issue and here is a clear step by step process to avoid this error.

我遇到了完全相同的问题,这里有一个明确的步骤来避免这个错误。

Step 1 - Installation ( Don't follow this step if you have already installed MongoDB ):

步骤1 -安装(如果您已经安装了MongoDB,请不要执行此步骤):

brew update
brew install mongodb

Step 2 - Run Mongo Daemon:

步骤2 -运行Mongo守护进程:

mkdir -p /data/db
sudo mongod

Step 3 - Run Mongo Shell Interface:

步骤3 -运行Mongo Shell接口:

mongo

In this sequence, I was able to run the mongo command without any error. I have also detailed the error trace and its solution on this blog.

在这个序列中,我能够运行mongo命令而不产生任何错误。我还在这个博客上详细介绍了错误跟踪和它的解决方案。

#3


21  

To solve your issue you need to follow the instructions which are then given to you by brew after you use "brew install mongodb".

为了解决您的问题,您需要遵循在您使用“brew安装mongodb”之后,由brew提供给您的指令。

To have launchd start mongodb at login:

要在登录时启动mongodb:

ln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents

Then to load mongodb now:

然后加载mongodb:

launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist

Or, if you don't want/need launchctl, you can just run:

或者,如果你不需要launchctl,你可以直接运行:

mongod --config /usr/local/etc/mongod.conf

You may be able to just run that last command, but it didn't work for me and I needed to run the second command. To save me in the future. I just ran the first command too. Hope that helps!

您可以运行最后一个命令,但是它对我不起作用,我需要运行第二个命令。在未来拯救我。我也刚刚运行了第一个命令。希望会有帮助!

EDIT Hrishi's method of using brew services mongodb start worked good for me. I think they should include this in the mongo docs.

编辑Hrishi使用brew服务mongodb的方法对我有好处。我认为他们应该把这个包括在mongo文档中。

#4


15  

In another tab, you can start the mongo shell with

在另一个选项卡中,您可以启动mongo shell。

mongod

mongod

Then return to the previous tab and try again. If you're having trouble setting up your mongoshell, check out this link on the mongo shell: http://docs.mongodb.org/manual/tutorial/manage-mongodb-processes/ or this link on installing mongodb: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/

然后返回到前面的选项卡,然后再试一次。如果您在设置mongoshell时遇到了麻烦,请查看mongoshell的这个链接:http://docs.mongodb.org/manual/tutorial/manage-mongodb-processes/或该链接安装mongodb: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/。

#5


7  

I was having the same issue when calling mongod from the command line.

从命令行调用mongod时,我遇到了同样的问题。

I resolved this by calling instead sudo mongod.

我把这个问题解决了,而不是叫sudo mongod。

#6


4  

I had the same error but a different root cause. Thought I'd post the solution here in case anyone else runs into the problem. I got this error after my Mac improperly shut down while I was running mongorestore -d foo dump/foo/.

我有同样的错误,但有不同的根源。我想在这里发布解决方案,以防其他人遇到问题。当我运行mongorestore -d foo dump/foo/时,Mac不正确地关闭后,我得到了这个错误。

tl;dr: I fixed the problem by removing the damaged foo.ns file along with foo.0, foo.1,... from my data folder /usr/local/var/mongodb/. Then I restarted the mongo server with brew services restart mongodb and I was back to normal.

我通过移除损坏的foo来解决这个问题。nsfile和foo一起。0 foo.1……从我的数据文件夹/ usr/local/var/mongodb/。然后我重新启动mongo服务器,brew服务重启mongodb,我恢复正常。

Details: I kept getting the error even after trying to start or restart the mongodb service via brew or launchctl. Eventually I ran mongod --dbpath /usr/local/var/mongodb and saw that the service was not actually starting, and the start sequence included the following error: [initandlisten] bad .ns file: /usr/local/var/mongodb/foo.ns [initandlisten] User Assertion: 10079:bad .ns file length, cannot open database I got rid of the bad .ns file and the rest of the data files, and the next time I started the service I was good to go.

细节:即使尝试通过brew或launchctl启动或重启mongodb服务,我仍然得到了错误。最终,我运行mongod——dbpath /usr/local/var/mongodb,并看到服务实际上并没有启动,而开始序列包含了以下错误:[initandlisten] bad .ns文件:/usr/local/var/mongodb/foo。ns [initandlisten]用户断言:10079:坏的。ns文件长度,不能打开数据库,我去掉了坏的。ns文件和其他的数据文件,而下次我开始服务时,我就很好了。

#7


3  

for me on osx, I had to kill old running instance, then restarting worked.

在osx上,我必须杀死旧的运行实例,然后重新开始工作。

$>ps -aef | grep mongo
502  8047     1   0 11:52AM ??         0:00.23 /usr/local/opt/mongodb/bin/mongod --config /usr/local/etc/mongod.conf 

$>sudo kill 8047

$>sudo mongod

#8


0  

My guess is that you do not have a running database while trying to access testing through the "mongo" command.

我的猜测是,在尝试通过“mongo”命令访问测试时,您没有运行数据库。

First run this command in terminal:

首先在终端运行此命令:

mongod 

Then open another terminal window and run:

然后打开另一个终端窗口并运行:

mongo

蒙戈

Everything should be working now.

现在一切都应该工作了。

#9


0  

My similar error is resolved by deleting "sudo rm /data/db/mongod.lock" file while trying to run mongod. Now u can run mongod and then mongo.

通过删除“sudo rm /data/db/mongod”来解决类似的错误。在试图运行mongod时锁定“文件”。现在你可以运行mongod和mongo了。

#10


0  

If you have already installed MongoDB then first try to run mongod as a sudo user, I was facing the issue because of not running mongod as a superuser.

如果您已经安装了MongoDB,那么首先尝试运行mongod作为sudo用户,我就面临这个问题,因为没有运行mongod作为超级用户。

I have pasted the o/p for both the commands(mongod and sudo mongod) at very bottom, you can check that too but

我已经在底部粘贴了o/p的命令(mongod和sudo mongod),你也可以检查一下。

First try this

第一次尝试这

sudo mongod

not this

不是这个

mongod

I had installed MongoDB on my MAC OS X Sierra 10.12.6 by by running the following command in sequence.

通过按顺序运行下面的命令,我在MAC OS X Sierra 10.12.6上安装了MongoDB。

brew update
brew install mongodb --devel
brew services start mongodb

then created a directory to which mongod process will write the data, this is optional as mongod process takes it by default, see this useful guide at https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/

然后创建一个目录,mongod进程将写入数据,这是可选的,因为mongod进程在默认情况下使用它,在https://docs.mongodb.com/manual/tutorial/install-mongodb- x/中看到这个有用的指南。

sudo mkdir -p /data/db

Finally started mongod process as follows

最后开始了蒙神的过程。

sudo mongod

Oputput of mongod (failed) and sudo mongod (succeeded) commands on my terminal.

mongod的Oputput(失败)和sudo mongod(成功的)命令在我的终端上。

MacBook-Pro-2:appscheck admin$ mongod
2017-12-10T08:12:06.166+0530 I CONTROL  [initandlisten] MongoDB starting : pid=2698 port=27017 dbpath=/data/db 64-bit host=MacBook-Pro-2.local
2017-12-10T08:12:06.166+0530 I CONTROL  [initandlisten] db version v3.4.10
2017-12-10T08:12:06.166+0530 I CONTROL  [initandlisten] git version: 078f28920cb24de0dd479b5ea6c66c644f6326e9
2017-12-10T08:12:06.166+0530 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2n  7 Dec 2017
2017-12-10T08:12:06.166+0530 I CONTROL  [initandlisten] allocator: system
2017-12-10T08:12:06.166+0530 I CONTROL  [initandlisten] modules: none
2017-12-10T08:12:06.166+0530 I CONTROL  [initandlisten] build environment:
2017-12-10T08:12:06.166+0530 I CONTROL  [initandlisten]     distarch: x86_64
2017-12-10T08:12:06.166+0530 I CONTROL  [initandlisten]     target_arch: x86_64
2017-12-10T08:12:06.166+0530 I CONTROL  [initandlisten] options: {}
2017-12-10T08:12:06.166+0530 I STORAGE  [initandlisten] exception in initAndListen: 20 Attempted to create a lock file on a read-only directory: /data/db, terminating
2017-12-10T08:12:06.166+0530 I NETWORK  [initandlisten] shutdown: going to close listening sockets...
2017-12-10T08:12:06.166+0530 I NETWORK  [initandlisten] shutdown: going to flush diaglog...
2017-12-10T08:12:06.167+0530 I CONTROL  [initandlisten] now exiting
2017-12-10T08:12:06.167+0530 I CONTROL  [initandlisten] shutting down with code:100


MacBook-Pro-2:appscheck admin$ sudo mongod
Password:
2017-12-10T08:12:14.084+0530 I CONTROL  [initandlisten] MongoDB starting : pid=2700 port=27017 dbpath=/data/db 64-bit host=MacBook-Pro-2.local
2017-12-10T08:12:14.084+0530 I CONTROL  [initandlisten] db version v3.4.10
2017-12-10T08:12:14.084+0530 I CONTROL  [initandlisten] git version: 078f28920cb24de0dd479b5ea6c66c644f6326e9
2017-12-10T08:12:14.084+0530 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2n  7 Dec 2017
2017-12-10T08:12:14.084+0530 I CONTROL  [initandlisten] allocator: system
2017-12-10T08:12:14.084+0530 I CONTROL  [initandlisten] modules: none
2017-12-10T08:12:14.084+0530 I CONTROL  [initandlisten] build environment:
2017-12-10T08:12:14.084+0530 I CONTROL  [initandlisten]     distarch: x86_64
2017-12-10T08:12:14.084+0530 I CONTROL  [initandlisten]     target_arch: x86_64
2017-12-10T08:12:14.084+0530 I CONTROL  [initandlisten] options: {}
2017-12-10T08:12:14.084+0530 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=7680M,session_max=20000,eviction=(threads_min=4,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-12-10T08:12:14.472+0530 I CONTROL  [initandlisten] 
2017-12-10T08:12:14.472+0530 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-12-10T08:12:14.472+0530 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-12-10T08:12:14.472+0530 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2017-12-10T08:12:14.472+0530 I CONTROL  [initandlisten] 
2017-12-10T08:12:14.472+0530 I CONTROL  [initandlisten] 
2017-12-10T08:12:14.472+0530 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
2017-12-10T08:12:14.560+0530 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2017-12-10T08:12:14.707+0530 I INDEX    [initandlisten] build index on: admin.system.version properties: { v: 2, key: { version: 1 }, name: "incompatible_with_version_32", ns: "admin.system.version" }
2017-12-10T08:12:14.707+0530 I INDEX    [initandlisten]      building index using bulk method; build may temporarily use up to 500 megabytes of RAM
2017-12-10T08:12:14.719+0530 I INDEX    [initandlisten] build index done.  scanned 0 total records. 0 secs
2017-12-10T08:12:14.720+0530 I COMMAND  [initandlisten] setting featureCompatibilityVersion to 3.4
2017-12-10T08:12:14.720+0530 I NETWORK  [thread1] waiting for connections on port 27017

Then I opened new terminal to start querying the MongoDB, it worked.

然后我打开新的终端开始查询MongoDB,它成功了。

MacBook-Pro-2:appscheck admin$ mongo
MongoDB shell version v3.4.10
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.10
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
    http://docs.mongodb.org/
Questions? Try the support group
    http://groups.google.com/group/mongodb-user
Server has startup warnings: 
2017-12-10T08:12:14.472+0530 I CONTROL  [initandlisten] 
2017-12-10T08:12:14.472+0530 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-12-10T08:12:14.472+0530 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-12-10T08:12:14.472+0530 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2017-12-10T08:12:14.472+0530 I CONTROL  [initandlisten] 
2017-12-10T08:12:14.472+0530 I CONTROL  [initandlisten] 
2017-12-10T08:12:14.472+0530 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
> show dbs;
admin  0.000GB
local  0.000GB
> use practice
switched to db practice
>

That's it.

就是这样。

#11


0  

I got this error after I upgraded to mongo 3.6 with homebrew.

在升级到mongo 3.6之后,我得到了这个错误。

The log /usr/local/var/log/mongodb/mongo.log contained the message shutting down with code:62. This error code means that the existing database is too old to run with the current version of mongo.

日志/usr/local/var/log/mongodb/mongo.日志中包含了关闭代码的消息:62。此错误代码意味着现有数据库太旧,无法运行当前版本的mongo。

I found 2 solutions in another SO question:

我在另一个问题中找到了两种解决方案:

  • Delete your database folder (/usr/local/var/mongodb)
  • 删除数据库文件夹(/usr/local/var/mongodb)
  • Or follow the upgrade procedure
  • 或遵循升级程序。

I chose to upgrade. In my case, that meant I had to downgrade to 3.4, run a command in the mongo console, then upgrade again. Mongo requires you to upgrade one major version at a time, so depending on how far back you were, there could be additional steps. The docs will guide you.

我选择升级。在我的例子中,这意味着我必须降级到3.4,在mongo控制台运行一个命令,然后再升级。Mongo要求您一次升级一个主要版本,所以根据您的支持程度,可能会有额外的步骤。医生会指导你的。

The brew switch * and brew services restart commands made swapping between versions relatively painless.

brew开关*和brew服务重启命令可以相对轻松地在不同版本之间进行交换。

#1


254  

It can happen when the mongodb service is not running on the mac. To start it, I tried

当mongodb服务没有在mac上运行时,就会发生这种情况。

brew services start mongodb

and it worked.

它工作。

Edit: According to the discussion on this PR on homebrew: https://github.com/Homebrew/homebrew/issues/30628

编辑:根据在homebrew上的讨论:https://github.com/homebrew/homebrew/es/30628。

brew services is deprecated, I looked around on SO and found these answers now answer the question: What is the correct way to start a mongod service on linux / OS X?

brew服务被弃用,我查看了一下,发现这些答案现在回答了一个问题:在linux / OS X上启动mongod服务的正确方法是什么?

#2


26  

I encountered the exact same issue and here is a clear step by step process to avoid this error.

我遇到了完全相同的问题,这里有一个明确的步骤来避免这个错误。

Step 1 - Installation ( Don't follow this step if you have already installed MongoDB ):

步骤1 -安装(如果您已经安装了MongoDB,请不要执行此步骤):

brew update
brew install mongodb

Step 2 - Run Mongo Daemon:

步骤2 -运行Mongo守护进程:

mkdir -p /data/db
sudo mongod

Step 3 - Run Mongo Shell Interface:

步骤3 -运行Mongo Shell接口:

mongo

In this sequence, I was able to run the mongo command without any error. I have also detailed the error trace and its solution on this blog.

在这个序列中,我能够运行mongo命令而不产生任何错误。我还在这个博客上详细介绍了错误跟踪和它的解决方案。

#3


21  

To solve your issue you need to follow the instructions which are then given to you by brew after you use "brew install mongodb".

为了解决您的问题,您需要遵循在您使用“brew安装mongodb”之后,由brew提供给您的指令。

To have launchd start mongodb at login:

要在登录时启动mongodb:

ln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents

Then to load mongodb now:

然后加载mongodb:

launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist

Or, if you don't want/need launchctl, you can just run:

或者,如果你不需要launchctl,你可以直接运行:

mongod --config /usr/local/etc/mongod.conf

You may be able to just run that last command, but it didn't work for me and I needed to run the second command. To save me in the future. I just ran the first command too. Hope that helps!

您可以运行最后一个命令,但是它对我不起作用,我需要运行第二个命令。在未来拯救我。我也刚刚运行了第一个命令。希望会有帮助!

EDIT Hrishi's method of using brew services mongodb start worked good for me. I think they should include this in the mongo docs.

编辑Hrishi使用brew服务mongodb的方法对我有好处。我认为他们应该把这个包括在mongo文档中。

#4


15  

In another tab, you can start the mongo shell with

在另一个选项卡中,您可以启动mongo shell。

mongod

mongod

Then return to the previous tab and try again. If you're having trouble setting up your mongoshell, check out this link on the mongo shell: http://docs.mongodb.org/manual/tutorial/manage-mongodb-processes/ or this link on installing mongodb: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/

然后返回到前面的选项卡,然后再试一次。如果您在设置mongoshell时遇到了麻烦,请查看mongoshell的这个链接:http://docs.mongodb.org/manual/tutorial/manage-mongodb-processes/或该链接安装mongodb: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/。

#5


7  

I was having the same issue when calling mongod from the command line.

从命令行调用mongod时,我遇到了同样的问题。

I resolved this by calling instead sudo mongod.

我把这个问题解决了,而不是叫sudo mongod。

#6


4  

I had the same error but a different root cause. Thought I'd post the solution here in case anyone else runs into the problem. I got this error after my Mac improperly shut down while I was running mongorestore -d foo dump/foo/.

我有同样的错误,但有不同的根源。我想在这里发布解决方案,以防其他人遇到问题。当我运行mongorestore -d foo dump/foo/时,Mac不正确地关闭后,我得到了这个错误。

tl;dr: I fixed the problem by removing the damaged foo.ns file along with foo.0, foo.1,... from my data folder /usr/local/var/mongodb/. Then I restarted the mongo server with brew services restart mongodb and I was back to normal.

我通过移除损坏的foo来解决这个问题。nsfile和foo一起。0 foo.1……从我的数据文件夹/ usr/local/var/mongodb/。然后我重新启动mongo服务器,brew服务重启mongodb,我恢复正常。

Details: I kept getting the error even after trying to start or restart the mongodb service via brew or launchctl. Eventually I ran mongod --dbpath /usr/local/var/mongodb and saw that the service was not actually starting, and the start sequence included the following error: [initandlisten] bad .ns file: /usr/local/var/mongodb/foo.ns [initandlisten] User Assertion: 10079:bad .ns file length, cannot open database I got rid of the bad .ns file and the rest of the data files, and the next time I started the service I was good to go.

细节:即使尝试通过brew或launchctl启动或重启mongodb服务,我仍然得到了错误。最终,我运行mongod——dbpath /usr/local/var/mongodb,并看到服务实际上并没有启动,而开始序列包含了以下错误:[initandlisten] bad .ns文件:/usr/local/var/mongodb/foo。ns [initandlisten]用户断言:10079:坏的。ns文件长度,不能打开数据库,我去掉了坏的。ns文件和其他的数据文件,而下次我开始服务时,我就很好了。

#7


3  

for me on osx, I had to kill old running instance, then restarting worked.

在osx上,我必须杀死旧的运行实例,然后重新开始工作。

$>ps -aef | grep mongo
502  8047     1   0 11:52AM ??         0:00.23 /usr/local/opt/mongodb/bin/mongod --config /usr/local/etc/mongod.conf 

$>sudo kill 8047

$>sudo mongod

#8


0  

My guess is that you do not have a running database while trying to access testing through the "mongo" command.

我的猜测是,在尝试通过“mongo”命令访问测试时,您没有运行数据库。

First run this command in terminal:

首先在终端运行此命令:

mongod 

Then open another terminal window and run:

然后打开另一个终端窗口并运行:

mongo

蒙戈

Everything should be working now.

现在一切都应该工作了。

#9


0  

My similar error is resolved by deleting "sudo rm /data/db/mongod.lock" file while trying to run mongod. Now u can run mongod and then mongo.

通过删除“sudo rm /data/db/mongod”来解决类似的错误。在试图运行mongod时锁定“文件”。现在你可以运行mongod和mongo了。

#10


0  

If you have already installed MongoDB then first try to run mongod as a sudo user, I was facing the issue because of not running mongod as a superuser.

如果您已经安装了MongoDB,那么首先尝试运行mongod作为sudo用户,我就面临这个问题,因为没有运行mongod作为超级用户。

I have pasted the o/p for both the commands(mongod and sudo mongod) at very bottom, you can check that too but

我已经在底部粘贴了o/p的命令(mongod和sudo mongod),你也可以检查一下。

First try this

第一次尝试这

sudo mongod

not this

不是这个

mongod

I had installed MongoDB on my MAC OS X Sierra 10.12.6 by by running the following command in sequence.

通过按顺序运行下面的命令,我在MAC OS X Sierra 10.12.6上安装了MongoDB。

brew update
brew install mongodb --devel
brew services start mongodb

then created a directory to which mongod process will write the data, this is optional as mongod process takes it by default, see this useful guide at https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/

然后创建一个目录,mongod进程将写入数据,这是可选的,因为mongod进程在默认情况下使用它,在https://docs.mongodb.com/manual/tutorial/install-mongodb- x/中看到这个有用的指南。

sudo mkdir -p /data/db

Finally started mongod process as follows

最后开始了蒙神的过程。

sudo mongod

Oputput of mongod (failed) and sudo mongod (succeeded) commands on my terminal.

mongod的Oputput(失败)和sudo mongod(成功的)命令在我的终端上。

MacBook-Pro-2:appscheck admin$ mongod
2017-12-10T08:12:06.166+0530 I CONTROL  [initandlisten] MongoDB starting : pid=2698 port=27017 dbpath=/data/db 64-bit host=MacBook-Pro-2.local
2017-12-10T08:12:06.166+0530 I CONTROL  [initandlisten] db version v3.4.10
2017-12-10T08:12:06.166+0530 I CONTROL  [initandlisten] git version: 078f28920cb24de0dd479b5ea6c66c644f6326e9
2017-12-10T08:12:06.166+0530 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2n  7 Dec 2017
2017-12-10T08:12:06.166+0530 I CONTROL  [initandlisten] allocator: system
2017-12-10T08:12:06.166+0530 I CONTROL  [initandlisten] modules: none
2017-12-10T08:12:06.166+0530 I CONTROL  [initandlisten] build environment:
2017-12-10T08:12:06.166+0530 I CONTROL  [initandlisten]     distarch: x86_64
2017-12-10T08:12:06.166+0530 I CONTROL  [initandlisten]     target_arch: x86_64
2017-12-10T08:12:06.166+0530 I CONTROL  [initandlisten] options: {}
2017-12-10T08:12:06.166+0530 I STORAGE  [initandlisten] exception in initAndListen: 20 Attempted to create a lock file on a read-only directory: /data/db, terminating
2017-12-10T08:12:06.166+0530 I NETWORK  [initandlisten] shutdown: going to close listening sockets...
2017-12-10T08:12:06.166+0530 I NETWORK  [initandlisten] shutdown: going to flush diaglog...
2017-12-10T08:12:06.167+0530 I CONTROL  [initandlisten] now exiting
2017-12-10T08:12:06.167+0530 I CONTROL  [initandlisten] shutting down with code:100


MacBook-Pro-2:appscheck admin$ sudo mongod
Password:
2017-12-10T08:12:14.084+0530 I CONTROL  [initandlisten] MongoDB starting : pid=2700 port=27017 dbpath=/data/db 64-bit host=MacBook-Pro-2.local
2017-12-10T08:12:14.084+0530 I CONTROL  [initandlisten] db version v3.4.10
2017-12-10T08:12:14.084+0530 I CONTROL  [initandlisten] git version: 078f28920cb24de0dd479b5ea6c66c644f6326e9
2017-12-10T08:12:14.084+0530 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2n  7 Dec 2017
2017-12-10T08:12:14.084+0530 I CONTROL  [initandlisten] allocator: system
2017-12-10T08:12:14.084+0530 I CONTROL  [initandlisten] modules: none
2017-12-10T08:12:14.084+0530 I CONTROL  [initandlisten] build environment:
2017-12-10T08:12:14.084+0530 I CONTROL  [initandlisten]     distarch: x86_64
2017-12-10T08:12:14.084+0530 I CONTROL  [initandlisten]     target_arch: x86_64
2017-12-10T08:12:14.084+0530 I CONTROL  [initandlisten] options: {}
2017-12-10T08:12:14.084+0530 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=7680M,session_max=20000,eviction=(threads_min=4,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-12-10T08:12:14.472+0530 I CONTROL  [initandlisten] 
2017-12-10T08:12:14.472+0530 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-12-10T08:12:14.472+0530 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-12-10T08:12:14.472+0530 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2017-12-10T08:12:14.472+0530 I CONTROL  [initandlisten] 
2017-12-10T08:12:14.472+0530 I CONTROL  [initandlisten] 
2017-12-10T08:12:14.472+0530 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
2017-12-10T08:12:14.560+0530 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2017-12-10T08:12:14.707+0530 I INDEX    [initandlisten] build index on: admin.system.version properties: { v: 2, key: { version: 1 }, name: "incompatible_with_version_32", ns: "admin.system.version" }
2017-12-10T08:12:14.707+0530 I INDEX    [initandlisten]      building index using bulk method; build may temporarily use up to 500 megabytes of RAM
2017-12-10T08:12:14.719+0530 I INDEX    [initandlisten] build index done.  scanned 0 total records. 0 secs
2017-12-10T08:12:14.720+0530 I COMMAND  [initandlisten] setting featureCompatibilityVersion to 3.4
2017-12-10T08:12:14.720+0530 I NETWORK  [thread1] waiting for connections on port 27017

Then I opened new terminal to start querying the MongoDB, it worked.

然后我打开新的终端开始查询MongoDB,它成功了。

MacBook-Pro-2:appscheck admin$ mongo
MongoDB shell version v3.4.10
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.10
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
    http://docs.mongodb.org/
Questions? Try the support group
    http://groups.google.com/group/mongodb-user
Server has startup warnings: 
2017-12-10T08:12:14.472+0530 I CONTROL  [initandlisten] 
2017-12-10T08:12:14.472+0530 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-12-10T08:12:14.472+0530 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-12-10T08:12:14.472+0530 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2017-12-10T08:12:14.472+0530 I CONTROL  [initandlisten] 
2017-12-10T08:12:14.472+0530 I CONTROL  [initandlisten] 
2017-12-10T08:12:14.472+0530 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
> show dbs;
admin  0.000GB
local  0.000GB
> use practice
switched to db practice
>

That's it.

就是这样。

#11


0  

I got this error after I upgraded to mongo 3.6 with homebrew.

在升级到mongo 3.6之后,我得到了这个错误。

The log /usr/local/var/log/mongodb/mongo.log contained the message shutting down with code:62. This error code means that the existing database is too old to run with the current version of mongo.

日志/usr/local/var/log/mongodb/mongo.日志中包含了关闭代码的消息:62。此错误代码意味着现有数据库太旧,无法运行当前版本的mongo。

I found 2 solutions in another SO question:

我在另一个问题中找到了两种解决方案:

  • Delete your database folder (/usr/local/var/mongodb)
  • 删除数据库文件夹(/usr/local/var/mongodb)
  • Or follow the upgrade procedure
  • 或遵循升级程序。

I chose to upgrade. In my case, that meant I had to downgrade to 3.4, run a command in the mongo console, then upgrade again. Mongo requires you to upgrade one major version at a time, so depending on how far back you were, there could be additional steps. The docs will guide you.

我选择升级。在我的例子中,这意味着我必须降级到3.4,在mongo控制台运行一个命令,然后再升级。Mongo要求您一次升级一个主要版本,所以根据您的支持程度,可能会有额外的步骤。医生会指导你的。

The brew switch * and brew services restart commands made swapping between versions relatively painless.

brew开关*和brew服务重启命令可以相对轻松地在不同版本之间进行交换。