programing

Mongoid 3 + Heroku(MongoHQ) 원인 모페드::오류::작업 실패

stoneblock 2023. 7. 3. 22:31

Mongoid 3 + Heroku(MongoHQ) 원인 모페드::오류::작업 실패

레일즈 3로, Mongoid 2.x에서 Mongoid 3.x로 업그레이드한 후, my Heroku + MongoHQ 설정이 작동하지 않습니다.재미있는 것은, 제 개발 및 테스트 프레임워크와 전체 테스트 세트가 잘 통과한다는 것입니다.

나는 내 mongoid.yml 파일에 문제가 있다고 생각하지만, 문서, 구글 및 스택 오버플로를 검색해 보았고 herku mongohq mongoid Mongo:를 포함하여 제안된 모든 형식을 사용했습니다.:연결 실패 또는 실제로는 다음과 같습니다.

7월 16일 업데이트:mongoid.yml 파일은 여러 가지를 시도한 후 + MongoHQ의 Jason이 제안한 내용 이후에 다음과 같이 보입니다.

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

(위 링크의 것과 본질적으로 동일하지만 uri를 사용한다는 점을 제외하고는 다른 방법으로 MONGOHQ_URL을 별도의 필드로 분할하려고 했지만 도움이 되지 않았습니다.)

저는 mongoid를 3.0.0rc로 설정하고 Gem 파일에 버전을 비워두려고 했습니다.github 버전은 HTTPS 인증서 같은 것 때문에 사용하지 못했기 때문에 여러 번 시도할 필요가 없었습니다.

액션 컨트롤러의 설명은 다음과 같습니다.

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"

그리고 내가 달릴 때

heroku run console 

이해합니다.

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> 

저는 모든 것을 검색하고, 여러 개의 github mongoid 이슈를 검토하고, 문서를 여러 번 읽었습니다. 그리고 저는 여기서 아이디어가 부족합니다.

다음에 제가 해봐야 할 것이 생각나는 것이 있나요?

업데이트 7월 16일: 이깃 푸쉬 헤로쿠 마스터(MongoHQ의 제이슨이 제안한 것을 수행한 후)에서 헤로쿠는 이렇게 말합니다.

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

업데이트 7월 16일: Jason & Kurt 씨가 말한 대로 했습니다(처음에는 번들 업데이트 몽고이드를 실행하는 것을 잊었지만, 그것도 도움이 되지 않았습니다).그러나 이제 오류가 변경되었습니다.

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

Ruby 1.9.3을 사용해야 합니다.1.9.3 사용 방법은 여기 Mongoid 설명서와 여기 Heroku 설명서를 참조하십시오.

저도 비슷한 오류가 발생하고 있었고, 저는 제 보석 파일을 포함하도록 변경했습니다.ruby '1.9.3'그리고 모든 것이 예상대로 다시 작동했습니다.

편집: @herb는 이것이 작동하기 위해서는 최신 버전의 번들러가 필요하다고 지적했습니다.gem install bundler --pre). 그렇지 않으면,ruby '1.9.3'Gem 파일에서 작동하지 않습니다.

기본 세션에 "options" 영역을 추가하고 옵션 중 하나로 "skip_version_check:true"를 추가합니다.

제이슨 몽고본사

해결 방법으로 herku config에서 uri를 하드코딩하면 효과가 있는 것 같습니다.

ex:

production:
  sessions:
    default:
      uri: "mongodb://heroku:xxxx@domain.mongohq.com:000/appyyyy"
      options:
        skip_version_check: true
        safe: true

0 클래스 오류는 <%= ENV['MONGOHQ_URL'] %>가 0을 반환하고 있었기 때문인 것 같습니다.

언급URL : https://stackoverflow.com/questions/11494134/mongoid-3-heroku-mongohq-cause-mopederrorsoperationfailure