sql >> Database teknologi >  >> NoSQL >> MongoDB

Mongoid samme indlejrede dokumenttyper for forskellige felter

Her er det bedste svar!

class Email
  include Mongoid::Document

  embeds_many :to_recipients, :class_name => "Recipient"
  embeds_many :cc_recipients, :class_name => "Recipient"
  embeds_many :bcc_recipients, :class_name => "Recipient"    
  embeds_one :from, :class_name => "Recipient"

  field :subject, type: String
  field :body_text, type: String
  field :body_html, type: String
end

class Recipient
  include Mongoid::Document
  field :email_address, type: String
  field :name, type: String
  validates :email_address, :presence => true
  embedded_in :emails
end


  1. Hvorfor virker denne mongo-art ikke i PHP?

  2. Hvorfor lua script blokere redis-server?

  3. MongoDB :forespørgsel efter dokumenter med to lige store felter, $match og $eq

  4. $cond operatør java kode