Rails Exception Mongo :: Error :: NoServerAvailable

I want to use MongoDB with my Rails application.

The error is not unusual, but none of the suggestions worked for me.

I installed mongodb using homebrew and followed the steps below for the same

brew update

brew install mongodb

sudo mkdir -p / data / db

sudo chmod 777 / data / db

brew click homebrew / services

I use brew services start mongodbto start my mongodb server and get the following response

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" } }

Along with this, I also start mongo

cd / usr / local / bin mongod

which begins as expected.

I created an application for rails without ActiveRecordand used a mongiodgem. Then I created the configuration file with rails g mongoid:configand added the file Mongoid.load! './config/mongoid.yml'to the application.rbconfiguration file to load.

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 local_threshold = 0.015):

, can not, , .

. , , - . /books/new, , , , , .

mongodb, , - , , .

, , . , , . .

- , mongodb. - . post, , mongod mongo, . , - , , , .

0
1

Mongod

$ mongod
0

Source: https://habr.com/ru/post/1693347/


All Articles