|
| 1 | +************* |
| 2 | +Common Errors |
| 3 | +************* |
| 4 | + |
| 5 | +.. default-domain:: mongodb |
| 6 | + |
| 7 | +.. contents:: On this page |
| 8 | + :local: |
| 9 | + :backlinks: none |
| 10 | + :depth: 2 |
| 11 | + :class: singlecol |
| 12 | + |
| 13 | + |
| 14 | +No Server is Available Matching Preference |
| 15 | +========================================== |
| 16 | + |
| 17 | +If you receive the following error: |
| 18 | + |
| 19 | +.. code-block:: ruby |
| 20 | + |
| 21 | + > client[:contacts].insert_one({ vpa: 'cool@cool'}) |
| 22 | + Mongo::Error::NoServerAvailable: No server is available matching preference: #<Mongo::ServerSelector::Primary:0x14987080 tag_sets=[] max_staleness=nil> using server_selection_timeout=30 and local_threshold=0.015 |
| 23 | + from /rvm/gems/ruby-2.4.2/gems/mongo-2.5.0/lib/mongo/server_selector/selectable.rb:115:in `select_server' |
| 24 | + from /rvm/gems/ruby-2.4.2/gems/mongo-2.5.0/lib/mongo/cluster.rb:246:in `next_primary' |
| 25 | + from /rvm/gems/ruby-2.4.2/gems/mongo-2.5.0/lib/mongo/retryable.rb:150:in `legacy_write_with_retry' |
| 26 | + from /rvm/gems/ruby-2.4.2/gems/mongo-2.5.0/lib/mongo/retryable.rb:103:in `write_with_retry' |
| 27 | + from /rvm/gems/ruby-2.4.2/gems/mongo-2.5.0/lib/mongo/collection.rb:422:in `block in insert_one' |
| 28 | + from /rvm/gems/ruby-2.4.2/gems/mongo-2.5.0/lib/mongo/client.rb:485:in `with_session' |
| 29 | + from /rvm/gems/ruby-2.4.2/gems/mongo-2.5.0/lib/mongo/collection.rb:421:in `insert_one' |
| 30 | + from (irb):6 |
| 31 | + from /rvm/rubies/ruby-2.4.2/bin/irb:11:in `<main>' |
| 32 | + |
| 33 | +This error was produced on Ruby Driver version 2.6.x and earlier. This error is |
| 34 | +raised when the driver is unable to connect to the server. In order to solve |
| 35 | +this, you can try the following: |
| 36 | + |
| 37 | +- Update the driver to the most recent 2.x release. |
| 38 | +- Ensure that the port number is correct in the URI/connection string, or the |
| 39 | + host list. |
| 40 | +- If you are connecting to Atlas, ensure that the firewall rules are configured |
| 41 | + correctly. See the documentation on `Cluster Security <https://www.mongodb.com/docs/atlas/setup-cluster-security/>`_. |
| 42 | +- If your application uses a forking web server, see the documentation on :ref:`Forking <forking>`. |
| 43 | + |
| 44 | +See more on this issue here: |
| 45 | +`RUBY-1281 <https://jira.mongodb.org/browse/RUBY-1281>`_. |
| 46 | + |
| 47 | + |
| 48 | +``OperationFailure`` When Reading ``local`` Database With Auth On |
| 49 | +================================================================= |
| 50 | + |
| 51 | +If you are getting the following error when trying to read the ``local`` database: |
| 52 | + |
| 53 | +.. code-block:: ruby |
| 54 | + |
| 55 | + Mongo::Error::OperationFailure: not authorized on local to execute command { find: "oplog.rs", filter: { ts: |
| 56 | + { $gte: Timestamp 1497449043000|0 } }, sort: { $natural: 1 } } (13) |
| 57 | + |
| 58 | +You can fix this by adjusting the roles your user has and ensuring that it has |
| 59 | +privileges to the local database. If you specifically want to access the oplog, |
| 60 | +you can also create a custom role with read access to the local database's |
| 61 | +``oplog.rs`` collection. You can find more information about role management |
| 62 | +`here <https://www.mongodb.com/docs/manual/reference/method/js-role-management/>`_. |
| 63 | + |
| 64 | +You can find more information about this issue here: |
| 65 | +`MONGOID-4446 <https://jira.mongodb.org/browse/MONGOID-4446>`_. |
| 66 | + |
| 67 | + |
| 68 | +``SocketTimeoutError`` and name resolution errors on EC2 |
| 69 | +======================================================== |
| 70 | + |
| 71 | +Some users reported getting the following error: |
| 72 | + |
| 73 | +.. code-block:: ruby |
| 74 | + |
| 75 | + Exception |
| 76 | + Mongo::Error::SocketTimeoutError |
| 77 | + Error |
| 78 | + execution expired |
| 79 | + /var/lib/gems/2.3.0/gems/mongo-2.5.0/lib/mongo/socket/ssl.rb:57:in `pack_sockaddr_in' |
| 80 | + /var/lib/gems/2.3.0/gems/mongo-2.5.0/lib/mongo/socket/ssl.rb:57:in `block (2 levels) in connect!' |
| 81 | + /var/lib/gems/2.3.0/gems/mongo-2.5.0/lib/mongo/socket.rb:199:in `handle_errors' |
| 82 | + /var/lib/gems/2.3.0/gems/mongo-2.5.0/lib/mongo/socket/ssl.rb:57:in `block in connect!' |
| 83 | + /usr/lib/ruby/2.3.0/timeout.rb:101:in `timeout' |
| 84 | + /var/lib/gems/2.3.0/gems/mongo-2.5.0/lib/mongo/socket/ssl.rb:56:in `connect!' |
| 85 | + /var/lib/gems/2.3.0/gems/mongo-2.5.0/lib/mongo/address.rb:172:in `connect_socket!' |
| 86 | + /var/lib/gems/2.3.0/gems/mongo-2.5.0/lib/mongo/server/connection.rb:86:in `connect!' |
| 87 | + /var/lib/gems/2.3.0/gems/mongo-2.5.0/lib/mongo/server/connectable.rb:84:in `ensure_connected' |
| 88 | + /var/lib/gems/2.3.0/gems/mongo-2.5.0/lib/mongo/server/connection.rb:256:in `write' |
| 89 | + |
| 90 | +This error was last reported on Ruby Driver version 2.5.1, so updating the driver |
| 91 | +can potentially solve this issue. A user has reported that they solved this issue |
| 92 | +as follows: |
| 93 | + |
| 94 | + DNS servers on EC2 are generated in /etc/resolv.conf by default. Following |
| 95 | + the answer `here <https://askubuntu.com/questions/157154/how-do-i-include-lines-in-resolv-conf-that-wont-get-lost-on-reboot?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa>`_ |
| 96 | + and setting the nameservers to Google NS I was able to fix this issue. |
| 97 | + |
| 98 | +You can find more information about this issue here: |
| 99 | +`MONGOID-4527 <https://jira.mongodb.org/browse/MONGOID-4527>`_. |
| 100 | + |
| 101 | + |
| 102 | +``Mongo::Auth::Unauthorized`` User is Not Authorized to Access |
| 103 | +============================================================== |
| 104 | + |
| 105 | +Some users reported getting the following error: |
| 106 | + |
| 107 | +.. code-block:: ruby |
| 108 | + |
| 109 | + Mongo::Auth::Unauthorized: User ... is not authorized to access ... |
| 110 | + |
| 111 | +After upgrading to Ruby Driver version 2.5+, the driver was changed to use |
| 112 | +the scram authorization mechanism by default. This error might be happen if the |
| 113 | +authorization mechanism your user was created with does not match the |
| 114 | +authorization mechanism used by the driver. You can specify the preferred |
| 115 | +authorization mechanism using the ``auth_mech`` option in your ``mongoid.yml`` |
| 116 | +file. |
| 117 | + |
| 118 | +See more on this issue here: |
| 119 | +`RUBY-1281 <https://jira.mongodb.org/browse/RUBY-1684>`_. |
| 120 | + |
0 commit comments