Rails异常Mongo ::错误:: NoServerAvailable

时间:2018-02-08 08:46:55

标签: mongodb macos exception ruby-on-rails-5 mongoid

我想在我的Rails应用程序中使用MongoDB。

错误并不少见,但没有一条建议对我有用。

我已经使用自制软件安装了mongodb,然后按照相同步骤进行操作

  

brew更新

     

brew install mongodb

     

sudo mkdir -p / data / db

     

sudo chmod 777 / data / db

     

brew tap homebrew / services

我使用brew services start mongodb启动我的mongodb服务器并获得以下响应

2018-02-08T12:27:59.072+0530 I CONTROL  [initandlisten] MongoDB starting : pid=39164 port=27017 dbpath=/data/db 64-bit host=C168s-iMac.local
2018-02-08T12:27:59.072+0530 I CONTROL  [initandlisten] db version v3.6.2
2018-02-08T12:27:59.072+0530 I CONTROL  [initandlisten] git version: 489d177dbd0f0420a8ca04d39fd78d0a2c539420
2018-02-08T12:27:59.072+0530 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2n  7 Dec 2017
2018-02-08T12:27:59.072+0530 I CONTROL  [initandlisten] allocator: system
2018-02-08T12:27:59.072+0530 I CONTROL  [initandlisten] modules: none
2018-02-08T12:27:59.072+0530 I CONTROL  [initandlisten] build environment:
2018-02-08T12:27:59.072+0530 I CONTROL  [initandlisten]     distarch: x86_64
2018-02-08T12:27:59.072+0530 I CONTROL  [initandlisten]     target_arch: x86_64
2018-02-08T12:27:59.072+0530 I CONTROL  [initandlisten] options: {}
2018-02-08T12:27:59.089+0530 I -        [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2018-02-08T12:27:59.089+0530 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=3584M,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),statistics_log=(wait=0),verbose=(recovery_progress),
2018-02-08T12:28:01.222+0530 I STORAGE  [initandlisten] WiredTiger message [1518073081:222686][39164:0x7fffa9db0340], txn-recover: Main recovery loop: starting at 2/18944
2018-02-08T12:28:01.330+0530 I STORAGE  [initandlisten] WiredTiger message [1518073081:330012][39164:0x7fffa9db0340], txn-recover: Recovering log 2 through 3
2018-02-08T12:28:01.442+0530 I STORAGE  [initandlisten] WiredTiger message [1518073081:442109][39164:0x7fffa9db0340], txn-recover: Recovering log 3 through 3
2018-02-08T12:28:02.563+0530 I CONTROL  [initandlisten] 
2018-02-08T12:28:02.563+0530 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-02-08T12:28:02.563+0530 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2018-02-08T12:28:02.563+0530 I CONTROL  [initandlisten] 
2018-02-08T12:28:02.563+0530 I CONTROL  [initandlisten] ** WARNING: This server is bound to localhost.
2018-02-08T12:28:02.563+0530 I CONTROL  [initandlisten] **          Remote systems will be unable to connect to this server. 
2018-02-08T12:28:02.563+0530 I CONTROL  [initandlisten] **          Start the server with --bind_ip <address> to specify which IP 
2018-02-08T12:28:02.563+0530 I CONTROL  [initandlisten] **          addresses it should serve responses from, or with --bind_ip_all to
2018-02-08T12:28:02.563+0530 I CONTROL  [initandlisten] **          bind to all interfaces. If this behavior is desired, start the
2018-02-08T12:28:02.563+0530 I CONTROL  [initandlisten] **          server with --bind_ip 127.0.0.1 to disable this warning.
2018-02-08T12:28:02.563+0530 I CONTROL  [initandlisten] 
2018-02-08T12:28:02.563+0530 I CONTROL  [initandlisten] 
2018-02-08T12:28:02.563+0530 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
2018-02-08T12:28:02.572+0530 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2018-02-08T12:28:02.572+0530 I NETWORK  [initandlisten] waiting for connections on port 27017
2018-02-08T12:28:09.302+0530 I NETWORK  [listener] connection accepted from 127.0.0.1:51073 #1 (1 connection now open)
2018-02-08T12:28:09.302+0530 I NETWORK  [conn1] received client metadata from 127.0.0.1:51073 conn: { application: { name: "MongoDB Shell" }, driver: { name: "MongoDB Internal Client", version: "3.6.2" }, os: { type: "Darwin", name: "Mac OS X", architecture: "x86_64", version: "17.2.0" } }

除此之外,我也开始使用mongo

  

cd / usr / local / bin   的mongod

按预期开始。

我在没有ActiveRecord的情况下创建了我的rails应用,并使用了mongiod gem。接下来,我使用rails g mongoid:config创建了配置文件,并在Mongoid.load! './config/mongoid.yml'文件中添加了application.rb,以便加载配置文件。

mongoid.yml的内容是

development:
  clients:
    default:
      database: mongo_db_demo_development
      hosts:
        - localhost:27017
test:
  clients:
    default:
      database: mongo_db_demo_test
      hosts:
        - localhost:27017
      options:
        read:
          mode: :primary
        max_pool_size: 1

我为Person创建了我的脚手架,并使用include Mongoid::Document按预期创建了模型。我继续使用人的索引作为root_path

当我运行rails服务器时,我收到以下错误

  

ActionView :: Template :: Error(没有服务器匹配首选项:#using server_selection_timeout = 30 and local_threshold = 0.015):

我知道它是rails的一个例外,但现在似乎无法解决它几个小时。

我提到this教程开始。奇怪的是,我成功地设置了应用程序访问它,第二天它没有任何更改就崩溃了。我可以访问图书的新页面/books/new,但似乎无法保存,因此很明显应用程序无法访问数据库。

我已经卸载mongodb两次想知道安装是否有问题,但似乎无法弄清楚什么是错误的。

我知道有许多类似的问题,但没有解决我的问题。我不明白我错过了什么,出错了。任何帮助表示赞赏。

由于

更新

我在某种程度上能够运行另一个有活动记录和mongodb的项目。 Here是一样的。我成功地将数据保存到post模型,证明mongodmongo正在运行并且设置正确完成。这意味着我在我的应用程序配置中遗漏了一些东西但是,我不知道。

0 个答案:

没有答案