title: Ruby connecting to external Mongo DB
body: <p>We have a main portal site (running Rails 4 with a PostgreSQL database), and an external image server (running Node.js with Mongo database). I'm trying to establish a connection from Rails to the database - I installed the mongo gem - <a href="https://docs.mongodb.org/ecosystem/drivers/ruby/" rel="nofollow">https://docs.mongodb.org/ecosystem/drivers/ruby/</a> - and have been following the guide, but got stuck on an odd key error that I can't seem to find any information on.</p>
  
  <p>The image server itself is running fine with no problems (it has a GUI interface that is working fine).</p>
  
  <p>In my controller (I changed the names and left out the passwords):</p>
  
  <pre><code>image_server = Mongo::Client.new([ 'image.companyname.com:####' ], :database =&gt; 'db-name')
  </code></pre>
  
  <p>It seems to connect:</p>
  
  <pre><code>D, [2015-11-11T00:41:22.730360 #9410] DEBUG -- : MONGODB | Adding image.companyname.com:#### to the cluster.
  </code></pre>
  
  <p>But then just spams this message over and over (and queries don't do anything but return this error even faster).</p>
  
  <pre><code>D, [2015-11-11T00:41:22.991386 #9410] DEBUG -- : MONGODB | key not found: "t"
  </code></pre>
  
  <p>Eventually it returns one error message as well, but keeps spamming the key not found error as well:</p>
  
  <pre><code>Mongo::Error::NoServerAvailable (No server is available matching preference: #&lt;Mongo::ServerSelector::Primary:0x007f5a943f6ee8 @options={"mode"=&gt;:primary, "database"=&gt;"db-name"}, @tag_sets=[], @server_selection_timeout=30&gt;):
  </code></pre>
  
  <p>app/controllers/admin/model_controller.rb:9:in `index'</p>
  
  <p>EDIT
  I even tried connect directly to the UNIX socket, and got the same error:</p>
  
  <pre><code>image_server = Mongo::Client.new('mongodb://image.companyname.com:####/path/to/socket/socketname.sock')
  </code></pre>
  
  <p>END EDIT</p>
  
  <p>I'm unsure what the heck this 'key not found "t"' error is, or how to even begin to diagnose this. I've messed with every single connection option I can think of, and nothing changes. Any ideas?</p>