我有這樣低於此示出的一些集合持有關係,testMaster和testDoc之間關係握持testDocMaster獲取從多個集合的數據在蒙戈
對於例如內:
testMaster {
_id: "Schema.Objectid",
name: "String" //master name
}
testDoc {
_id : Schema.ObjectId,
name: "String", //doc name
other datas
}
testDocMaster {
masterId: "_id of the testMaster table",
docId : "_id of the above testDoc"
}
對於每個主入口,我們預計有很多關係,
什麼是如果我有masterId,則從testDoc表中獲取數據的最佳方法。
關係集合通常是MongoDB中的一種反模式。當你有一個n:m的關係時,你應該添加一個數組字段到其中一個文件,它保存着對另一個文件的引用。我知道,當你習慣於關係數據庫時,這聽起來很不直觀。但MongoDB不是關係數據庫。 – Philipp
@ Philipp,這根本不是一個準確的說法。一些關係最好表現爲嵌入式數組,一些最好的表現形式是鏈接的獨立集合。請參閱我的答案在這裏解釋http://stackoverflow.com/questions/13897305/how-would-you-model-customer-order-ordertem-product-in-nosql-database/13898439#13898439 –