我有一個Group
和User
架構,而adding group
你映射users
它。 A user
可以屬於多個groups
。有沒有辦法,我可以涉及兩個對象ID的貓鼬
我有一個以下PartySchema
它有user
和groups
。
var Party = new Schema({
name : String,
user: [{ type: Schema.ObjectId, ref: 'Person' }],
groups: [{ type: Schema.ObjectId, ref: 'Group' }]
});
我顯示在table structure
映射上像一個複選框在我Party
頁面,選擇組和用戶的「Party
」
-- Groups
---- Users
您可以選擇一組和其用戶在checkbox style[Parent[Group]-Children[User]]
。在PartySchema
中,我將groups
和users
分別更新爲reference
和不作爲文檔。在PartySchema
中的。
user: [{ type: Schema.ObjectId, ref: 'Person' }],
groups: [{ type: Schema.ObjectId, ref: 'Group' }]
我只獲得兩個group
ID和users
ID,這個我不能說爲"Group1"
巴蒂爾已經選擇而不是"Group2"
,因爲從早期的關係「謝恩」屬於兩個組,但同時添加派對我從Group2中選擇「shane」而不是Group1。
在編輯派對頁面時,我再次獲取所有組和用戶,在此我無法說在組2中選擇了「Shane」作爲「組1」也具有「Shane」和「Group2」已經shane,我們將其保存爲參考,而不是作爲文檔。
-- Group1
---- Shane [Not selected]
-- Group1
---- Shane [selected]
確定的,而不是用戶列表u需要像'USER_GROUP: {user:{type:Schema.ObjectId,ref:'Person'},group:{type:Schema.ObjectId,ref:'Group'}}],''Schema.Types.Mixed' –
just logic not sure if語法雖然是 –
@aishwatsingh:哇...感謝很多老兄,所以我會傳遞兩個與這個數組相關的對象ID嗎?如果你知道,你能展示更多細節嗎? – Shane