2011-04-11 1 views
0

상표, 모델 및 장비의 세 가지 모델이 있습니다. 브랜드 임베디드 모델, 모델 임베디드 장비. OSX everithing에 대한 개발에서 잘 작동하지만, EC2 Ubuntu 10.04 장비의 생산에서 모든 유효성 검사를 통과하고, 작성 및 저장 방법에 대해 진실을 말하며, "장비가 성공적으로 생성되었습니다"라고 출력하지만 db에는 추가되지 않습니다.몽고이 (Mongoid)의 제작 과정에서의 이상한 행동 : 레코드를 저장했지만 데이터베이스에 나타나지 않았 음

ruby-1.9.2-p180 :002 > b = Brand.create!(:title => "Volvo", :logo_file_name => "some_logo.png") 
=> #<Brand _id: 4da29833b177070722000002, _type: nil, _id: BSON::ObjectId('4da29833b177070722000002'), title: "Volvo", logo_file_name: "some_logo.png", logo_content_type: nil, logo_file_size: nil, logo_updated_at: nil, active: true> 
ruby-1.9.2-p180 :007 > m = b.models.create!(:title => "740") 
=> #<Model _id: 4da29893b177070722000004, _type: nil, _id: BSON::ObjectId('4da29893b177070722000004'), title: "740", active: true> 
ruby-1.9.2-p180 :024 > e = m.equipment.create!(:title => "1.6 Turbo", :start => 1987, :stop => 1993) 
=> #<Equipment _id: 4da29a42b177070722000006, _type: nil, _id: BSON::ObjectId('4da29a42b177070722000006'), title: "1.6 Turbo", start: 1987, stop: 1993, acive: true, image_file_name: nil, image_content_type: nil, image_file_size: nil, image_updated_at: nil> 
ruby-1.9.2-p180 :025 > bb = Brand.last 
=> #<Brand _id: 4da29833b177070722000002, _type: nil, _id: BSON::ObjectId('4da29833b177070722000002'), title: "Volvo", logo_file_name: "some_logo.png", logo_content_type: nil, logo_file_size: nil, logo_updated_at: nil, active: true> 
ruby-1.9.2-p180 :026 > mm = bb.models.last 
=> #<Model _id: 4da29893b177070722000004, _type: nil, _id: BSON::ObjectId('4da29893b177070722000004'), title: "740", active: true> 
ruby-1.9.2-p180 :027 > ee = mm.equipment.last 
=> nil 

ruby-1.9.2-p180 :032 > mm.equipment 
=> [] 

ruby-1.9.2-p180 :033 > e = m.equipment.new 
=> #<Equipment _id: 4da29b15b177070722000008, _type: nil, _id: BSON::ObjectId('4da29b15b177070722000008'), title: nil, start: nil, stop: nil, acive: true, image_file_name: nil, image_content_type: nil, image_file_size: nil, image_updated_at: nil> 
ruby-1.9.2-p180 :034 > e.title = "1.8 SLE" 
=> "1.8 SLE" 
ruby-1.9.2-p180 :035 > e.start = 1988 
=> 1988 
ruby-1.9.2-p180 :036 > e.stop = 1994 
=> 1994 
ruby-1.9.2-p180 :037 > e.save! 
=> true 
ruby-1.9.2-p180 :038 > bb = Brand.last 
=> #<Brand _id: 4da29833b177070722000002, _type: nil, _id: BSON::ObjectId('4da29833b177070722000002'), title: "Volvo", logo_file_name: "some_logo.png", logo_content_type: nil, logo_file_size: nil, logo_updated_at: nil, active: true> 
ruby-1.9.2-p180 :040 > mm = bb.models.last 
=> #<Model _id: 4da29893b177070722000004, _type: nil, _id: BSON::ObjectId('4da29893b177070722000004'), title: "740", active: true> 
ruby-1.9.2-p180 :041 > ee = mm.equipment.last 
=> nil 

왜 이런 일이 발생할 수 있습니까?

답변

0

유효성이 성공적 일 때 true가 반환됩니다.은 반드시 mongodb에 대한 지속성이 아닙니다.

기본적으로 대부분의 드라이버 (몽고이 어에 대해 확실하지 않음)는 '불만과 잊기'방식으로 mongo에 글을 쓰고 레코드를 저장하는 데 문제가 있는지 여부에 대한 서버의 응답을 기다리지 않습니다.

기본적으로 '안전 모드'를 켜고 http://mongoid.org/docs/installation/configuration.html으로 설정할 수 있습니다. '발사 및 잊어'대신 변경 사항이 지속될 때까지 드라이버 블록이 적용됩니다.

아마도 드라이버/몽고 이드가 응답 (안전하지 않은 쓰기)을 기다리고 있기 때문에 놓친 서버에서 오류가 발생했을 것입니다.

+0

글쎄, 콘솔에서 everithing 여전히 (같은 제목으로 다른 하나를 만들려면, 비록 내가 아직도 데이터베이스에서 찾을 수 없지만 생성하고 심지어 알리는) 동일하지만, 웹 인터페이스에서 나는 'Mongo :: OperationFailure (: Modifier spec은 이미 비 객체를 나타내는 이름을 가진 캡슐화 객체의 존재를 의미하거나 다른 $ set 절에서 참조됩니다.) app/controllers /equipment_controller.rb:51:in'create ' ' –

+0

구성했습니다. 어떻게 든 mongod의 오래된 버전을 가지고 있습니다 - 1.2.2, 그래서 1.8.1로 업데이트해야하고 모든 것이 잘 작동합니다. 고맙습니다! –