0
device.rb을 저장하는 동안힘 고유의 필드 포함 된 문서를
class Device
include Mongoid::Document
field :devui, type: String
field :name, type: String
belongs_to :user
embeds_many :responses
end
은 몇 가지 데이터는, 나는 나에게 그것에 id 필드와 JSON을 제공하는 외부 서버에서 가져올. 어떤 응답을 삽입하려고하면 id 필드가 반복되고 mongo는 _id가 일부 데이터에 대해 json 배열로 오는 ID와 같아집니다.
devices_controller.rb
class Response
include Mongoid::Document
field :dataFrame, type: String
embedded_in :device
end
답변 해 주셔서 감사합니다. 임베디드 문서에서 고유 색인을 만들 수 있습니까? @device_data [: id]를 고유하게 유지하려고합니다. 그렇게하는 방법? – ashusvirus
그건 내가 잘 모르겠다. 그러나 당신은 * id *, 즉 validates_uniqueness_of : whatever_name_you_chose_for_id_field'에 대한 중복 엔트리를 막기 위해'Response' 클래스에 검증을 추가 할 수 있습니다. –