Mongoid 3 + Heroku(MongoHQ)导致Moped :: Errors :: OperationFailure [英] Mongoid 3 + Heroku (MongoHQ) cause Moped::Errors::OperationFailure

查看:136
本文介绍了Mongoid 3 + Heroku(MongoHQ)导致Moped :: Errors :: OperationFailure的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Rails 3,从Mongoid 2.x升级到Mongoid 3.x后,我的Heroku + MongoHQ设置停止工作。有趣的是,我的发展&测试框架和我的整个测试套件都很好。



我怀疑问题在于我的mongoid.yml文件,但我试过搜索文档,google& stackoverflow,并使用了所有建议的格式,包括: heroku mongohq和mongoid Mongo :: ConnectionFailure 或实际上是这样的: https://gist.github.com/2900804



7月16日更新:这是我的mongoid.yml文件在多次尝试后的样子+ 在MongoHQ的Jason建议之后:

 开发:
会话:
默认值:
数据库:开发
主机:
- localhost:27017

测试:
会话:
默认值:
数据库:测试
主机:
- localhost :27017

生产:
会话:
默认值:
uri:<%= ENV ['MONGOHQ_URL']%>
选项:
skip_version_check:true
safe:true

(根据我的理解,它基本上与上面的链接中的一样,只是它使用了uri;我尝试了另一种方式,将MONGOHQ_URL拆分为单独的字段,但它没有帮助)



我尝试将mongoid设置为3.0.0rc,并将版本留在我的Gemfile中。使用github版本由于HTTPS证书或其他原因而失败,所以我没有多次尝试它。



动作控制器说的是这样的:

  Moped :: Errors :: OperationFailure in Home#index 

显示/ app / app / views / home / index .html.haml在第2行出现的位置:

操作:#< Moped :: Protocol :: Command
@ length = 68
@ request_id = 4
@ response_to = 0
@ op_code = 2004
@flags = [:slave_ok]
@full_collection_name =。$ cmd
@ skip = 0
@limit = -1
@selector = {:count =>:posts,:query => {}}
@ fields = nil>
失败,出现错误db assertion failure

当我运行时

  heroku run console 

我得到这个:

  irb(main):052:0> Location.create! 
NoMethodError:未定义方法`[]'为nil:NilClass
from /app/vendor/bundle/ruby/1.9.1/gems/moped-1.1.1/lib/moped/node.rb: 74:在`block in command'
from /app/vendor/bundle/ruby/1.9.1/gems/moped-1.1.1/lib/moped/node.rb:522:in`[]'
from /app/vendor/bundle/ruby/1.9.1/gems/moped-1.1.1/lib/moped/node.rb:522:in`block(3 levels)in flush'
from /app/vendor/bundle/ruby/1.9.1/gems/moped-1.1.1/lib/moped/node.rb:521:in`map'
from /app/vendor/bundle/ruby/1.9 .1 / gems / moped-1.1.1 / lib / moped / node.rb:521:在'block(2 levels)in flush'
from /app/vendor/bundle/ruby/1.9.1/gems /moped-1.1.1/lib/moped/node.rb:113:in`ensure_connected'
from /app/vendor/bundle/ruby/1.9.1/gems/moped-1.1.1/lib/moped /node.rb:517:in`block in flush'
from /app/vendor/bundle/ruby/1.9.1/gems/moped-1.1.1/lib/moped/node.rb:532:in `logging'
from /app/vendor/bundle/ruby/1.9.1/gems/moped-1.1.1/lib/moped/node.rb:516:in`flush'
from /app/vendor/bundle/ruby/1.9.1/gems/moped-1.1.1/lib/moped/node.rb:505:in`process'
from / app / vendor / bundle / ruby​​ / 1.9.1 / gems / moped-1.1.1 / lib / moped / node.rb:70:在`command'中
来自/app/vendor/bundle/ruby/1.9.1/gems/moped-1.1。 1 / lib / moped / node.rb:356:在'refresh'中
来自/app/vendor/bundle/ruby/1.9.1/gems/moped-1.1.1/lib/moped/cluster.rb: 101:在`block in refresh'
from /app/vendor/bundle/ruby/1.9.1/gems/moped-1.1.1/lib/moped/cluster.rb:114:in`each'$ b $ / from /app/vendor/bundle/ruby/1.9.1/gems/moped-1.1.1/lib/moped/cluster.rb:114:in`refresh'
from / app / vendor / bundle / ruby / 1.9.1 / gems / moped-1.1.1 / lib / moped / cluster.rb:67:在`节点'
... 15个级别...
from / app / vendor / bundle / ruby​​ / 1.9.1 / gems / activesupport-3.2.6 / lib / active_support / callbacks.rb:405:在__run_callback'
from /app/vendor/bundle/ruby/1.9.1/gems/ activesupport-3.2.6 / lib / active_support / callbacks.rb:385:在_run_save_callbacks'
from / app / vendor / b undle / ruby​​ / 1.9.1 / gems / activesupport-3.2.6 / lib / active_support / callbacks.rb:81:在`run_callbacks'
from /app/vendor/bundle/ruby/1.9.1/gems/ mongoid-3.0.1 / lib / mongoid / callbacks.rb:98:在`run_callbacks'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.1/lib/mongoid/从/app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.1/lib/mongoid/persistence/operations/insert.rb'准备'
:persistence / insertion.rb:23: 26:在`persist'
/app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.1/lib/mongoid/persistence.rb:50:in`insert'
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.1/lib/mongoid/persistence.rb:251:in`block in create!'
from / app / vendor / bundle /ruby/1.9.1/gems/mongoid-3.0.1/lib/mongoid/threaded/lifecycle.rb:173:in`_creating'
from /app/vendor/bundle/ruby/1.9.1/gems /mongoid-3.0.1/lib/mongoid/persistence.rb:249:in`create!'$(from irb)
:52
from /app/vendor/bundle/ruby/1.9.1/宝石/ railties-3.2.6 / LIB / RAI ls / commands / console.rb:47:在`start'
/app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb: 8:在`开始'
从/app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/commands.rb:41:in`< top(必填) >'脚本/导轨中
:6:'require'
脚本/导轨:6:在< main>'irb(main):053:0>

我想我已经搜索了一切,运行多个github mongoid问题,多次阅读文档。 ..我在这里没有什么想法了。



任何想到的东西我都应该尝试下一步?

更新7月16日:这是Heroku在我推grato heroku master的时候说的话(在做完MongoHQ的Jason建议之后):
$ b

  git push heroku master 
计数对象:7,完成。
增量压缩使用多达16个线程。
压缩对象:100%(4/4),完成。
写入对象:100%(4/4),372字节,完成。
共计4(delta 3),重用0(delta 0)

-----> Heroku接收推送
-----> Ruby / Rails应用程序检测到
----->使用Bundler安装依赖项1.2.0.pre
正在运行:bundle install --without development:test --path vendor / bundle --binstubs bin / --deployment
使用rake(0.9.2.2)
使用i18n(0.6.0)
使用multi_json(1.3.6)
使用activesupport(3.2.6)
使用构建器(3.0.0)
#.. 。缩短这个#
使用libv8(3.3.10.4)
使用moped(1.1.2)
使用origin(1.0.4)
使用mongoid(3.0.0.rc)
使用omniauth(1.1.0)
使用quimby(0.4.5)
使用bundler(1.2.0.pre)
使用rails(3.2.6)
使用therubyracer(0.10.1)
使用thin(1.3.1)
您的软件包已完成!它已安装到./vendor/bundle
清理捆绑器缓存。
----->编写config / database.yml以从DATABASE_URL读取
----->为Rails资产管道准备应用程序
运行:rake资产:预编译
完成资产预编译(31.24秒)
-----> Rails插件注入
注入rails_log_stdout
注入rails3_serve_static_assets
----->发现过程类型
Procfile声明类型 - > (无)
Ruby / Rails的默认类型 - >控制台,耙子,网络,工人
----->编译的段塞大小是18.7MB
----->启动完成,v92
http://xxxxx.herokuapp.com部署到Heroku

到git@heroku.com:xxxxx.git
b2d97xy..7b0aczy master - > master

UPDATE 2 July 16th:did as Jason&库尔特先生说(首先忘记运行包更新mongoid,但这也没有帮助)。但现在错误发生了变化:

  Home#索引中的NoMethodError 

显示/ app / app / views / home / index.html.haml在第2行中出现:

未定义方法`[]'为零:NilClass

提取的源代码#2):

1:%h1最近的帖子
2: - if @ posts.length> 0


解决方案

您将需要使用Ruby 1.9.3。请参阅Mongoid文档此处和Heroku文档 here 关于如何使用1.9.3。



我也遇到类似的错误,并且我改变了我的gemfile以包含 ruby​​'1.9.3',并且所有事情都按预期工作。



编辑:
@herb指出你需要最新版本的打包工具才能工作( gem install bundler --pre ) 。否则,Gemfile中的 ruby​​'1.9.3'将不起作用。


With Rails 3, after upgrading from Mongoid 2.x to Mongoid 3.x, my Heroku + MongoHQ setup stopped working. Funny thing is, that my development & test frameworks and my whole test suite passes just fine.

I suspect the problem is with my mongoid.yml file, but I've tried searching the docs, google & stackoverflow, and used all the suggested formats, including this: heroku mongohq and mongoid Mongo::ConnectionFailure or actually this: https://gist.github.com/2900804

UPDATED July 16th: This is how my mongoid.yml file looks, after trying multiple things + After what Jason from MongoHQ suggested:

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

test:
  sessions:
    default:
      database: test
      hosts:
        - localhost:27017

production:
  sessions:
    default:
      uri: <%= ENV['MONGOHQ_URL'] %>
      options:
        skip_version_check: true
        safe: true

(to my understanding, it is essentially the same as the one in the links above, except that it uses the uri; I tried the other way, splitting the MONGOHQ_URL into the separate fields as well, but it didn't help)

I've tried setting mongoid as 3.0.0rc and leaving the version blank in my Gemfile. Using the github version failed due to HTTPS certificates or something, so I didn't bother trying it multiple times.

What the action controller says is this:

Moped::Errors::OperationFailure in Home#index

Showing /app/app/views/home/index.html.haml where line #2 raised:

The operation: #<Moped::Protocol::Command
  @length=68
  @request_id=4
  @response_to=0
  @op_code=2004
  @flags=[:slave_ok]
  @full_collection_name=".$cmd"
  @skip=0
  @limit=-1
  @selector={:count=>:posts, :query=>{}}
  @fields=nil>
failed with error "db assertion failure"

and when I run

heroku run console 

.. I get this:

irb(main):052:0> Location.create!
NoMethodError: undefined method `[]' for nil:NilClass
    from /app/vendor/bundle/ruby/1.9.1/gems/moped-1.1.1/lib/moped/node.rb:74:in `block in command'
    from /app/vendor/bundle/ruby/1.9.1/gems/moped-1.1.1/lib/moped/node.rb:522:in `[]'
    from /app/vendor/bundle/ruby/1.9.1/gems/moped-1.1.1/lib/moped/node.rb:522:in `block (3 levels) in flush'
    from /app/vendor/bundle/ruby/1.9.1/gems/moped-1.1.1/lib/moped/node.rb:521:in `map'
    from /app/vendor/bundle/ruby/1.9.1/gems/moped-1.1.1/lib/moped/node.rb:521:in `block (2 levels) in flush'
    from /app/vendor/bundle/ruby/1.9.1/gems/moped-1.1.1/lib/moped/node.rb:113:in `ensure_connected'
    from /app/vendor/bundle/ruby/1.9.1/gems/moped-1.1.1/lib/moped/node.rb:517:in `block in flush'
    from /app/vendor/bundle/ruby/1.9.1/gems/moped-1.1.1/lib/moped/node.rb:532:in `logging'
    from /app/vendor/bundle/ruby/1.9.1/gems/moped-1.1.1/lib/moped/node.rb:516:in `flush'
    from /app/vendor/bundle/ruby/1.9.1/gems/moped-1.1.1/lib/moped/node.rb:505:in `process'
    from /app/vendor/bundle/ruby/1.9.1/gems/moped-1.1.1/lib/moped/node.rb:70:in `command'
    from /app/vendor/bundle/ruby/1.9.1/gems/moped-1.1.1/lib/moped/node.rb:356:in `refresh'
    from /app/vendor/bundle/ruby/1.9.1/gems/moped-1.1.1/lib/moped/cluster.rb:101:in `block in refresh'
    from /app/vendor/bundle/ruby/1.9.1/gems/moped-1.1.1/lib/moped/cluster.rb:114:in `each'
    from /app/vendor/bundle/ruby/1.9.1/gems/moped-1.1.1/lib/moped/cluster.rb:114:in `refresh'
    from /app/vendor/bundle/ruby/1.9.1/gems/moped-1.1.1/lib/moped/cluster.rb:67:in `nodes'
... 15 levels...
    from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:405:in `__run_callback'
    from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:385:in `_run_save_callbacks'
    from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:81:in `run_callbacks'
    from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.1/lib/mongoid/callbacks.rb:98:in `run_callbacks'
    from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.1/lib/mongoid/persistence/insertion.rb:23:in `prepare'
    from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.1/lib/mongoid/persistence/operations/insert.rb:26:in `persist'
    from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.1/lib/mongoid/persistence.rb:50:in `insert'
    from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.1/lib/mongoid/persistence.rb:251:in `block in create!'
    from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.1/lib/mongoid/threaded/lifecycle.rb:173:in `_creating'
    from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.1/lib/mongoid/persistence.rb:249:in `create!'
    from (irb):52
    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:47:in `start'
    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:8:in `start'
    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'irb(main):053:0> 

I think I've googled everything, run through multiple github mongoid issues, read the documentation multiple times ... and I'm running out of ideas here.

Anything come to mind I should try next?

UPDATE July 16th: this is what Heroku says when I git push heroku master (After doing what Jason from MongoHQ suggested):

git push heroku master
Counting objects: 7, done.
Delta compression using up to 16 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 372 bytes, done.
Total 4 (delta 3), reused 0 (delta 0)

-----> Heroku receiving push
-----> Ruby/Rails app detected
-----> Installing dependencies using Bundler version 1.2.0.pre
       Running: bundle install --without development:test --path vendor/bundle --binstubs bin/ --deployment
       Using rake (0.9.2.2)
       Using i18n (0.6.0)
       Using multi_json (1.3.6)
       Using activesupport (3.2.6)
       Using builder (3.0.0)
            # ... shortened this #
       Using libv8 (3.3.10.4)
       Using moped (1.1.2)
       Using origin (1.0.4)
       Using mongoid (3.0.0.rc)
       Using omniauth (1.1.0)
       Using quimby (0.4.5)
       Using bundler (1.2.0.pre)
       Using rails (3.2.6)
       Using therubyracer (0.10.1)
       Using thin (1.3.1)
       Your bundle is complete! It was installed into ./vendor/bundle
       Cleaning up the bundler cache.
-----> Writing config/database.yml to read from DATABASE_URL
-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       Asset precompilation completed (31.24s)
-----> Rails plugin injection
       Injecting rails_log_stdout
       Injecting rails3_serve_static_assets
-----> Discovering process types
       Procfile declares types      -> (none)
       Default types for Ruby/Rails -> console, rake, web, worker
-----> Compiled slug size is 18.7MB
-----> Launching... done, v92
       http://xxxxx.herokuapp.com deployed to Heroku

To git@heroku.com:xxxxx.git
   b2d97xy..7b0aczy  master -> master

UPDATE 2 July 16th: did as Jason & MrKurt said (first forgot to run bundle update mongoid, but that didn't help either). Now the error changed, though:

NoMethodError in Home#index

Showing /app/app/views/home/index.html.haml where line #2 raised:

undefined method `[]' for nil:NilClass

Extracted source (around line #2):

    1: %h1 Most recent posts
    2: - if @posts.length > 0

解决方案

You will need to use Ruby 1.9.3. See Mongoid documentation here and Heroku documentation here on how to use 1.9.3.

I was also getting similar errors, and I changed my gemfile to include ruby '1.9.3' and everything worked as expected again.

Edit: @herb pointed out that you need the latest version of bundler for this to work (gem install bundler --pre). Otherwise, ruby '1.9.3' in your Gemfile will not work.

这篇关于Mongoid 3 + Heroku(MongoHQ)导致Moped :: Errors :: OperationFailure的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆