通过 heroku 播种 mongoDB 时出错

Error when seeding mongoDB thru heroku

你好,我有一个基于 heroku 构建的应用程序,但我似乎无法让 mlab 数据库工作。它似乎连接但是当我 运行 heroku 运行 rake db:setup 我得到一个错误并且看不到它是什么。

我升级到付费帐户,但这并没有解决问题。请帮我解决这个问题。这是我的 mongoid.yml 文件

# Tell Mongoid which environment this configuration is for. 
production:   
  sessions:
  default:
  uri: <%= ENV['MONGOLAB_URI'] %>

development:   
  sessions:
  default:
  database: myapp_development
  hosts:
    - localhost:27017
  options:   options:

test:   
  sessions:
  default:
    database: myapp_test
    hosts:
      - localhost:27017
      options:
      read: primary
      max_retries: 1
      retry_interval: 0

我的错误非常长,我似乎看不到最上面的几行,但这是我能看到的最上面的几行。

/app/vendor/bundle/ruby/2.2.0/gems/moped-2.0.7/lib/moped/operation/read.rb:56:in `block (2 levels) in execute' /app/vendor/bundle/ruby/2.2.0/gems/moped-2.0.7/lib/moped/node.rb:118:in `block in connection' /app/vendor/bundle/ruby/2.2.0/gems/connection_pool-2.2.0/lib/connection_pool.rb:64:in `block (2 levels) in with' /app/vendor/bundle/ruby/2.2.0/gems/connection_pool-2.2.0/lib/connection_pool.rb:63:in `handle_interrupt' /app/vendor/bundle/ruby/2.2.0/gems/connection_pool-2.2.0/lib/connection_pool.rb:63:in `block in with' /app/vendor/bundle/ruby/2.2.0/gems/connection_pool-2.2.0/lib/connection_pool.rb:60:in `handle_interrupt' /app/vendor/bundle/ruby/2.2.0/gems/connection_pool-2.2.0/lib/connection_pool.rb:60:in `with' /app/vendor/bundle/ruby/2.2.0/gems/moped-2.0.7/lib/moped/node.rb:116:in `connection' /app/vendor/bundle/ruby/2.2.0/gems/moped-2.0.7/lib/moped/operation/read.rb:52:in `block in execute' /app/vendor/bundle/ruby/2.2.0/gems/moped-2.0.7/lib/moped/node.rb:608:in `[]' /app/vendor/bundle/ruby/2.2.0/gems/moped-2.0.7/lib/moped/node.rb:608:in `block (3 levels) in flush’

感谢您的帮助。

顺便说一句,我是 运行ning mongoid 4.0.2 和 rails 2.2.1

--更新--

我运行 heroku run rake --trace db:setup

我收到了这个回复...

Running rake --trace db:setup on truenumbers-beta.... up, run.9099 ** Invoke db:setup (first_time) ** Invoke db:create (first_time) ** Invoke environment (first_time) ** Execute environment ** Execute db:create ** Invoke db:mongoid:create_indexes (first_time) ** Invoke environment ** Invoke db:mongoid:load_models (first_time) ** Execute db:mongoid:load_models ** Execute db:mongoid:create_indexes D, [2016-03-29T19:51:17.573001 #3] DEBUG -- : MOPED: 10.164.48.254:11460 COMMAND database=admin command={:ismaster=>1} runtime: 15.4384ms D, [2016-03-29T19:51:17.594073 #3] DEBUG -- : MOPED: 10.158.94.215:11460 COMMAND database=admin command={:ismaster=>1} runtime: 10.7151ms D, [2016-03-29T19:51:17.611470 #3] DEBUG -- : MOPED: 10.164.48.254:11460 COMMAND database=heroku_q1xh85jr command={:getlasterror=>1, :w=>1} runtime: 1.3616ms D, [2016-03-29T19:51:17.611875 #3] DEBUG -- : MOPED: 10.164.48.254:11460 INSERT database=heroku_...db collection=system.indexes documents=[{:ns=>"heroku_...db.fs.files", :key=>{:filename=>1}, :name=>"filename_1"}] flags=[] D, [2016-03-29T19:51:17.611965 #3] DEBUG -- : COMMAND database=heroku_...db command={:getlasterror=>1, :w=>1} runtime: 10.7461ms D, [2016-03-29T19:51:17.618998 #3] DEBUG -- : MOPED: 10.164.48.254:11460 COMMAND database=heroku_...db command={:getlasterror=>1, :w=>1} runtime: 2.2909ms D, [2016-03-29T19:51:17.619499 #3] DEBUG -- : MOPED: 10.164.48.254:11460 INSERT database=heroku_...db collection=system.indexes documents=[{:ns=>"heroku_...db.fs.files", :key=>{:aliases=>1}, :name=>"aliases_1"}] flags=[] D, [2016-03-29T19:51:17.619588 #3] DEBUG -- : COMMAND database=heroku_...db command={:getlasterror=>1, :w=>1} runtime: 6.9291ms D, [2016-03-29T19:51:17.635347 #3] DEBUG -- : MOPED: 10.164.48.254:11460 COMMAND database=heroku_...db command={:getlasterror=>1, :w=>1} runtime: 1.2759ms D, [2016-03-29T19:51:17.635548 #3] DEBUG -- : MOPED: 10.164.48.254:11460 INSERT database=heroku_...db collection=system.indexes documents=[{:ns=>"heroku_...db.fs.files", :key=>{:uploadDate=>1}, :name=>"uploadDate_1"}] flags=[] D, [2016-03-29T19:51:17.635637 #3] DEBUG -- : COMMAND database=heroku_...db command={:getlasterror=>1, :w=>1} runtime: 15.4409ms D, [2016-03-29T19:51:17.641401 #3] DEBUG -- : MOPED: 10.164.48.254:11460 COMMAND database=heroku_...db command={:getlasterror=>1, :w=>1} runtime: 1.2005ms D, [2016-03-29T19:51:17.641598 #3] DEBUG -- : MOPED: 10.164.48.254:11460 INSERT database=heroku_...db collection=system.indexes documents=[{:ns=>"heroku_...db.fs.files", :key=>{:md5=>1}, :name=>"md5_1"}] flags=[] D, [2016-03-29T19:51:17.641683 #3] DEBUG -- : COMMAND database=heroku_...db command={:getlasterror=>1, :w=>1} runtime: 5.4224ms I, [2016-03-29T19:51:17.641804 #3] INFO -- : MONGOID: Created indexes on Mongoid::GridFs::Fs::File: I, [2016-03-29T19:51:17.641914 #3] INFO -- : MONGOID: Index: {:filename=>1}, Options: {} I, [2016-03-29T19:51:17.641988 #3] INFO -- : MONGOID: Index: {:aliases=>1}, Options: {} I, [2016-03-29T19:51:17.642066 #3] INFO -- : MONGOID: Index: {:uploadDate=>1}, Options: {} I, [2016-03-29T19:51:17.642166 #3] INFO -- : MONGOID: Index: {:md5=>1}, Options: {} D, [2016-03-29T19:51:17.648954 #3] DEBUG -- : MOPED: 10.164.48.254:11460 COMMAND database=heroku_...db command={:getlasterror=>1, :w=>1} runtime: 1.1073ms D, [2016-03-29T19:51:17.649090 #3] DEBUG -- : MOPED: 10.164.48.254:11460 INSERT database=heroku_...db collection=system.indexes documents=[{:unique=>true, :ns=>"heroku_...db.fs.chunks", :key=>{:files_id=>1, :n=>-1}, :name=>"files_id_1_n_-1"}] flags=[] D, [2016-03-29T19:51:17.649137 #3] DEBUG -- : COMMAND database=heroku_...db command={:getlasterror=>1, :w=>1} runtime: 5.3409ms I, [2016-03-29T19:51:17.649182 #3] INFO -- : MONGOID: Created indexes on Mongoid::GridFs::Fs::Chunk: I, [2016-03-29T19:51:17.649234 #3] INFO -- : MONGOID: Index: {:files_id=>1, :n=>-1}, Options: {:unique=>true} D, [2016-03-29T19:51:17.656835 #3] DEBUG -- : MOPED: 10.164.48.254:11460 COMMAND database=heroku_...db command={:getlasterror=>1, :w=>1} runtime: 1.0796ms D, [2016-03-29T19:51:17.656969 #3] DEBUG -- : MOPED: 10.164.48.254:11460 INSERT database=heroku_...db collection=system.indexes documents=[{:background=>true, :ns=>"heroku_...db.tenants", :key=>{:invitation_token=>1}, :name=>"invitation_token_1"}] flags=[] D, [2016-03-29T19:51:17.657016 #3] DEBUG -- : COMMAND database=heroku_...db command={:getlasterror=>1, :w=>1} runtime: 7.2313ms D, [2016-03-29T19:51:17.663727 #3] DEBUG -- : MOPED: 10.164.48.254:11460 COMMAND database=heroku_...db command={:getlasterror=>1, :w=>1} runtime: 1.1747ms D, [2016-03-29T19:51:17.663903 #3] DEBUG -- : MOPED: 10.164.48.254:11460 INSERT database=heroku_...db collection=system.indexes documents=[{:background=>true, :ns=>"heroku_...db.tenants", :key=>{:invitation_by_id=>1}, :name=>"invitation_by_id_1"}] flags=[] D, [2016-03-29T19:51:17.663989 #3] DEBUG -- : COMMAND database=heroku_...db command={:getlasterror=>1, :w=>1} runtime: 6.2813ms I, [2016-03-29T19:51:17.664065 #3] INFO -- : MONGOID: Created indexes on Tenant: I, [2016-03-29T19:51:17.664166 #3] INFO -- : MONGOID: Index: {:invitation_token=>1}, Options: {:background=>true} I, [2016-03-29T19:51:17.664240 #3] INFO -- : MONGOID: Index: {:invitation_by_id=>1}, Options: {:background=>true} D, [2016-03-29T19:51:17.672419 #3] DEBUG -- : MOPED: 10.164.48.254:11460 COMMAND database=heroku_...db command={:getlasterror=>1, :w=>1} runtime: 1.3468ms D, [2016-03-29T19:51:17.672824 #3] DEBUG -- : MOPED: 10.164.48.254:11460 INSERT database=heroku_...db collection=system.indexes documents=[{:background=>true, :ns=>"heroku_...db.managers", :key=>{:invitation_token=>1}, :name=>"invitation_token_1"}] flags=[] D, [2016-03-29T19:51:17.672911 #3] DEBUG -- : COMMAND database=heroku_...db command={:getlasterror=>1, :w=>1} runtime: 7.8967ms D, [2016-03-29T19:51:17.679652 #3] DEBUG -- : MOPED: 10.164.48.254:11460 COMMAND database=heroku_...db command={:getlasterror=>1, :w=>1} runtime: 1.7443ms D, [2016-03-29T19:51:17.679844 #3] DEBUG -- : MOPED: 10.164.48.254:11460 INSERT database=heroku_...db collection=system.indexes documents=[{:background=>true, :ns=>"heroku_...db.managers", :key=>{:invitation_by_id=>1}, :name=>"invitation_by_id_1"}] flags=[] D, [2016-03-29T19:51:17.680187 #3] DEBUG -- : COMMAND database=heroku_...db command={:getlasterror=>1, :w=>1} runtime: 6.4280ms I, [2016-03-29T19:51:17.681679 #3] INFO -- : MONGOID: Created indexes on Manager: I, [2016-03-29T19:51:17.682260 #3] INFO -- : MONGOID: Index: {:invitation_token=>1}, Options: {:background=>true} I, [2016-03-29T19:51:17.682339 #3] INFO -- : MONGOID: Index: {:invitation_by_id=>1}, Options: {:background=>true} D, [2016-03-29T19:51:17.690098 #3] DEBUG -- : MOPED: 10.164.48.254:11460 COMMAND database=heroku_...db command={:getlasterror=>1, :w=>1} runtime: 2.1209ms D, [2016-03-29T19:51:17.698085 #3] DEBUG -- : MOPED: 10.164.48.254:11460 INSERT database=heroku_...db collection=system.indexes documents=[{:background=>true, :ns=>"heroku_...db.blog_posts", :key=>{:tags=>1}, :name=>"tags_1"}] flags=[] D, [2016-03-29T19:51:17.698350 #3] DEBUG -- : COMMAND database=heroku_...db command={:getlasterror=>1, :w=>1} runtime: 14.8885ms D, [2016-03-29T19:51:17.714160 #3] DEBUG -- : MOPED: 10.164.48.254:11460 COMMAND database=heroku_...db command={:getlasterror=>1, :w=>1} runtime: 8.2012ms D, [2016-03-29T19:51:17.715702 #3] DEBUG -- : MOPED: 10.164.48.254:11460 INSERT database=heroku_...db collection=system.indexes documents=[{:background=>true, :ns=>"heroku_...db.blog_posts", :key=>{:keywords=>1}, :name=>"keywords_1"}] flags=[] D, [2016-03-29T19:51:17.715800 #3] DEBUG -- : COMMAND database=heroku_...db command={:getlasterror=>1, :w=>1} runtime: 16.5160ms D, [2016-03-29T19:51:17.731378 #3] DEBUG -- : MOPED: 10.164.48.254:11460 COMMAND database=heroku_...db command={:getlasterror=>1, :w=>1} runtime: 6.8590ms D, [2016-03-29T19:51:17.732511 #3] DEBUG -- : MOPED: 10.164.48.254:11460 INSERT database=heroku_...db collection=system.indexes documents=[{:background=>true, :ns=>"heroku_...db.blog_posts", :key=>{:type=>1}, :name=>"type_1"}] flags=[] D, [2016-03-29T19:51:17.732602 #3] DEBUG -- : COMMAND database=heroku_...db command={:getlasterror=>1, :w=>1} runtime: 15.9511ms I, [2016-03-29T19:51:17.732759 #3] INFO -- : MONGOID: Created indexes on Blog::Post: I, [2016-03-29T19:51:17.732872 #3] INFO -- : MONGOID: Index: {:tags=>1}, Options: {:background=>true} I, [2016-03-29T19:51:17.732999 #3] INFO -- : MONGOID: Index: {:keywords=>1}, Options: {:background=>true} I, [2016-03-29T19:51:17.733300 #3] INFO -- : MONGOID: Index: {:type=>1}, Options: {:background=>true} ** Invoke db:seed (first_time) ** Invoke environment ** Execute db:seed D, [2016-03-29T19:51:23.970070 #3] DEBUG -- : MOPED: 10.164.48.254:11460 QUERY database=heroku_...db collection=tenants selector={"email"=>"lizeth_larson@pollich.io"} flags=[] limit=-1 skip=0 batch_size=nil fields={:_id=>1} runtime: 4.9172ms

它似乎正在创建数据库但无法为其设定种子。然而,当我去查看数据库时,他们什么都没有,这让我觉得也许它开始构建数据库,当种子失败时,它会破坏它所做的。

问题原来是我在开发中使用的数据库是 MongoDB 的旧版本。我升级到 MongoDB 5,稍作修改后一切正常。