2011-08-22 33 views
0

我試圖插入一個有多個嵌入式文檔的文檔,但我一直無法確定這樣的文檔的結構。如何使用Ruby API在MongoDB中嵌入多個文檔?

我在大多數地方使用Mongoid,但需要執行批處理文檔插入。

我已經試過如下:

def build_records_array(records) 
     records.collect do |record| 
      record.raw_attributes["identifier"] = record.identifiers.collect { |identifier| identifier.raw_attributes } 
      record.raw_attributes 
     end 
    end # self.build_records_array 

然而,標識符不顯示嵌入式文檔時,我打電話插入。我剛剛在我的父文檔中遇到了一堆垃圾。

嵌入式文檔的適當結構是什麼?

+0

您是否在添加新數據後保存文檔? – skayred

+0

對不起,直到現在還沒有看到您的評論。我正在執行一個插入與我在這裏建立的陣列,所以是的。 – LeakyBucket

回答

0

所以,我只是有一個錯字。在考慮我的問題時,我沒有考慮過Mongoid。在玩Mongo Driver來檢索Mongoid創建的記錄後,我發現我擁有的所有東西都只有屬性名稱。

def build_records_array(records) 
    records.collect do |record| 
    record.raw_attributes["identifiers"] = record.identifiers.collect { |identifier| identifier.raw_attributes } 
    record.raw_attributes 
    end 
end # build_records_array